import { Toast } from "vant";
// import cDyPopup from "./diyFormPopup";
import deliveryMap from "components/delivery_map";
import yzAddressList from "components/ui_components/yz_addressList/index";
import yzSubscribe from "components/ui_components/yz_subscribe";
import yz_uploader from "components/ui_components/yz_uploader";
import yzMyinfo from "components/ui_components/yz_myinfo";
import location from "components/ui_components/yz_addressList/location";
import order_invoice from "./order_components/invoice";
import addGoodsModule from "./order_components/addGoods";
import diyfrom from "components/diyform";
import invoicePop from "./components/invoice-pop";
import cityDeliveryDay from "./components/city-delivery-day";
import agencySaleman from "./order_components/agency-saleman";
import broadnetCard from "./components/broadnet-card/broadnetCard";

const TAG_ACTION_BUY = "-2"; // 直接购买
const TAG_ACTION_CART = "-1"; // 1购物车结算
var _goodsId = "";
var _optionsId = "";
var _total = 1;
var currentAddId = "";
// var currentAddress = {};
var _cart_ids = [];
var _packagJson = {};

var location_loading = 0; //防止频繁定位，后面考虑优化封装在getLocation()解决

export default {
  data() {
    return {
      local_life:{
        need_mobile:false,
      },
      currentAddress: {},
      noSupportDispatch: [], //不需要支持的配送方式，value为对应的dispatch_type_id
      root_tag: "", // 预下单的标识
      pre_order_url: "", // 预下单的请求url
      order_url: "", // 提交订单的请求url
      order_other_json: {}, // 每种类型下单的格外的请求数据
      isCartsOrder: false, // 判断是不是购物车下单类型

      popCode: "",
      showPop: false,

      clicktag: 0,
      good_clicktag: 0,

      order_data: "",
      // 积分自定义名称
      integral: window.localStorage.integral,
      // 爱心值自定义名称
      love_name: window.localStorage.love_name,
      goodsInfo: {},
      order: {},
      realname: "", // 收件人
      mobile: "",
      address: "",
      price: 0,
      showAddress: false,
      yzAddressListOptions: {}, //地址组件配置信息（可选）
      // 新优惠券
      coupon_size_new: false,
      coupons_new: [],
      popupCouponSpecs_new: false,
      use_coupon_size_new: 0,
      checkCouponList_new: [],
      // 优惠券
      coupons: [],
      popupCouponSpecs: false,
      coupon_size: 0,
      checkCouponList: [],
      use_coupon_size: 0,
      stepper_show: 0,
      is_coupon_SELE: false,
      coupons_temp: {}, //折叠优惠券input框model
      timeoutId: null, //防抖，防止折叠优惠券频繁触发

      // 积分抵扣 其他抵扣
      checkDeductionList: [],

      // 跨境
      isTaxGoods: false,
      // explain_title: "",
      // explain_content: "",

      // O2O部分
      storeCarts: [],
      store_id: 0,
      store_info: {},
      linkinfo: {
        mobile: "",
        name: ""
      },
      selected: 0,
      dispatch: [],

      // 个人信息和修改
      getParams_status: false, //是否已请求接口
      myRealname: "",
      myIdcard: "",
      showMyinfo: false,
      showFrom: false,

      isRent: false, // 租赁商品标识
      checkList: [], // 权益商品选择列表
      isRightChoose: false, // 是否选择权益商品

      rentTime: [], // 租期
      rentFree: "", // 可以免租的件数

      isOpenRight: false, // 是否开启会员权益开关

      currentIndex: "999",

      agreement: false, // 同意租赁协议
      agreementShow: false,

      AgreementPay: "", // 是否显示支付协议
      agreementPay: false, // 同意支付协议
      agreementPayShow: false, // 支付协议

      agreeCon: {}, // 租赁协议
      rent_deposit_free: 0, // 免押件数
      rent_free: 0, // 免租件数

      cup_notice: true, // 优惠券标识
      isShowCoupon: true, //是否显示优惠券
      submit_active: true,

      defaultAddress: {},

      note: [], // 留言
      service_fee: [], //服务费、运费说明
      taxInclusive: [], //含税
      for_serviceFee_status: false, //是否已遍历完成，避免van-checkbox-group 的change

      // 发票
      isShowInvoice: false,
      invoiceData: {
        papery_status: "",
        electron_status: ""
      },
      invoice_list: {},
      addressData: {}, //地址数据
      show_address: true,
      store_carry: {},

      // 续费商品
      goods_id: "",
      // 添加的name
      total_items: [],
      discount_amount_items: [],

      isGetAgreementPay: false, //判断是否已经请求了支付协议接口

      service_fee_items: {}, //服务费
      tax_fee_items: {}, //含税

      distributionUserName: "",
      distributionUserMobile: "",

      isOpenTeam: false, //是否为一键开团
      isJoinTeam: false, //是否为去参团

      isPhoto: false, //开启相册商品，true为相册商品
      fileList1: [], //相册路径链接
      max_count: 9, //最大上传张数
      min_count: 1, //最小上传张数
      storeNo_photo: false,

      defaultSelfCarry: "",
      isQuest_ing: true, //是否正在请求数据中
      form_data_id: "", //提交自定义表单后返回的表单id，
      deliverName: "自提点", //自提点自定义名称
      o2odeliverName: "自提点", //门店自提点自定义名称
      o2oSelfCarry: {},

      dyFormPopup: false,
      dfData: {},
      goodDYDormID: null,
      activeDYGoodID: null,
      activeFormDataID: null,
      dyDescription: null,
      dyTiitle: "",
      dyThumb: null, //表单图片
      oldOrder_data: [], //用于保存保存商品自定义表单后的数据

      is_region: 0,

      delivery_note: "", //门店配送说明
      delivery_area: [[116.403322, 39.920255]], // 配送范围经纬度
      locations: [116.403322, 39.920255], //门店经纬度
      is_show_store_delivery: false, //是否显示门店配送范围
      is_open_store_delivery: false, //是否开启门店配送
      locationName: "", //经纬度
      deliveryScopeShow: false,
      district_id: 0, //地址区域id
      address_name: "", //行政区名称
      is_custom: 0, //0 默认地图搜索，1 行政区搜索

      show_domain: false,
      shop_domain: "", //绑定域名
      isCueCoupon: false, //提示优惠券选择，只提示一次
      openCueCoupon: false,
      plugin_id: "", //应用市场plugin_id===58的时候要请求另外一个接口

      orderLocationObj: { positioning_success: 0, province: "", city: "" }, //下单添加定位地址（业绩区域）

      fromStock: "", // 是否是云库存商品
      is_cps: false, //聚合cps标识
      cpsType: "2", //1,直冲  2,卡券
      cpsTxt: "", //直冲帐号

      // 话费慢充
      show_recharge_mobile: "",
      recharge_tips: "",
      recharge_mobile: "",

      deliveryTimeParams: {}, //交易设置-收货地址管理-关闭地址是否需要区域
      deliveryTimeParamsTime: [],
      shop_delivery_day: "",
      shop_delivery_time: "",
      shop_delivery_dayPicker: false,
      shop_delivery_timePicker: false,

      // 自定义表单
      hasGoodOpenDF: false,
      //上门安装 插件名：live-install
      minDate: new Date(),
      installDate: null, //预约时间(10位时间戳)
      install_comment: "", //安装备注，不要超过120个字符
      location: {}, //定位信息
      showLocation: false,
      showInstallPop: false,

      subTemplate: "",
      storeSearchBtn: {}, //门店搜索插件自定义下单页按钮
      default_deduction: 0, //判断积分抵扣默认是否开启
      reserveName: "",
      reservePhone: "",
      reserveDate: "",
      // 预约扣除积分
      reserve_deduction: "",
      //预约扣除爱心值
      reserve_deduction_love: "",
      delivery_amount: 0, // 起送金额
      // 折扣自定义字段
      deduction_lang: "",
      phone_bill_pro_goods: false, //是否话费充值pro版，根据url是否有mobile来判断
      // supp_adress:'',
      supp_point: {
        lng: "",
        lat: "",
        address: ""
      },
      recommend_goods: [], //满额包邮推荐商品
      // 电费充值规格组合id
      electricity_Guide: "",
      electricity: false,
      // 充值户号
      eleUser: [],
      ele_no_showAdress: false,

      //运费说明
      ferightExplainPop: false,
      freightExplain: {},

      costSpecShow: false,
      selectCommunityShow: false,
      serviceRegionShow: false,

      //同城配送
      cityDelivery: null,
      cityDelivery_community: {},
      cityDelivery_community_id: 0,
      cityDelivery_deliveryTime: {},
      yz_subscribe_disabled: false,

      self_member_id: "",
      plugin_setting: "", //插件信息 获取默认地址
      camilo_resources_coupon_type: "", //插件id：140 卡券商品 1直冲2卡券
      recharge_number: "",
      number_isFocus: false,
      reserve_order: {
        service_id: "",
        obj_id: "",
        begin_time: "",
        customer_name: "",
        customer_tel: ""
      },

      addressList_caller: "", //地址组件调用着，识别是地址调用还是发票插件调用
      //油卡充值
      oil_mobile: "",
      oil_account: "",
      oil_pre_id: "",

      consigneeName: "", // 自提点提货人自定义
      consigneeMobile: "", // 自提点提货人手机号
      vip_show: false,
      hideDispatch: false,
      delivery_information: 0,
      address_codeEnable: false,
      codeShow: false,

      //联联周边游
      orderShowIdCard: 0,
      orderShowDate: 0,
      idCard: "",
      customerName: "",
      customerPhoneNumber: "",
      memo: "",
      is_diy_form_jump: 0, // 下单跳转表单填写
      travelAroundTime: "", //使用时间
      showTravel: false,
      travelTime: new Date().getTime(),
      travelMinDate: new Date(),
      bookingShowAddress: "",

      //蛋糕叔叔
      cakeCity: "", //城市信息
      cakeLat: "",
      cakeLng: "",
      cakeShipType: "", //第三方的配送方式
      cakeShipDate: "", //配送日期
      shipTimeText: "", //	配送时间
      shopDetail: "", //自提门店地址
      shopName: "", //自提门店名称
      shopId: "",
      deliveryDates: [],
      storeList: [], //门店列表
      cakeDeliveryArr: [], //获取所有的配送方式
      cakeCurrentTime: new Date().getTime(), //当前时间
      cakeEndTime: "",
      cakeStartTime: "",
      cakeMoblie: "",
      cakeText: "",
      takeDates: [],
      cakeChecked: false, //是否填写手机号
      showCake: false, //配送时间弹窗
      cakeTimeShow: false,
      cakeStoreShow: false, //门店列表
      canTake: 0, //是否支持门店自提自提
      canSame: 0, //是否支持快递配送配送
      canShip: 0, // 是否支持商户自配送配送
      deliveryArr: [],
      shopCakeArr: [],
      show_add_address: true,
      deliveryAmount: "", //运费
      // 咖啡机插件开关
      coffee_machine_open_state: false,
      coffeeDay: "",
      coffee_goods_ids: "",
      yz_lease_time: {
        days: 0,
        lease_term_id: ""
      },
      isRentSetting: false,
      storeTable: null, //门店餐桌扫码
      distribution_couponData: [],
      distribution_couponSpecs: false,
      distribution_coupon_ids: [],
      extra_info: {},//创建订单额外参数,
      noteShow:false,
      cloud_note:{},
      // 广电对接
      broadnet_card: false
    };
  },

  /**
   *  预下单页面:
   *  params : packagJson  changeSelfCarry address_data create district_id  pointId exchangeData
   *
   *  query : tag level_id  team_id goodsId  optionsId total store_id  isCash  distributionUserName distributionUserMobile
   *          orderType  mark team_id option_level_id at_id
   *          leader_id  order_id  activity_id cart_ids
   *  */
  deactivated() {
    this.initAdress();
  },
  activated() {
    this.first_default = "";
    this.initData();
    this.handleQueryData();
    if ((this.$route.query.orderShowDate ?? "") !== "") {
      this.orderShowDate = this.$route.query.orderShowDate;
    }

    // 重新计算
    if (this.selected == "10") {
      // 定位
      this.fun
        .getLocation("正在定位")
        .then(res => {
          // this.supp_adress = res.address;
          let ares = this.fun.bd_encrypt(res.point.lng, res.point.lat);
          this.supp_point.lng = ares.lng;
          this.supp_point.lat = ares.lat;
          this.supp_point.address = res.address;
        })
        .catch(err => {});
    }

    let yz_basic_info = JSON.parse(window.localStorage.getItem("yz_basic_info")) || {};
    if (yz_basic_info?.plugin_setting?.address_code?.enable) {
      this.address_codeEnable = true;
    }
    this.initAdress();
  },
  computed: {
    goodFittle_coffee(id, array) {
      return function(id, array) {
        let fittle = false;
        for (let index = 0; index < array.length; index++) {
          if (id == array[index]) {
            fittle = true;
          }
        }
        return fittle;
      };
    },
    appointmentLang() {
      if (this.$store.state.shopLanguage.reserve_simple) {
        return this.$store.state.shopLanguage.reserve_simple;
      } else {
        return { reserve_obj: "预约人员", service: "服务" };
      }
    }
  },
  methods: {
    async tap_noteShow(item){
      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.service-note.detail", { id: item.id }, "");
      if(result){
        this.cloud_note = data;
        this.noteShow = true;
      }else{
        this.$toast(msg);
      }
      console.log(item)
    },
    closeonGoBackTitle() {
      this.dyFormPopup = false;
    },
    initAdress() {
      //地址组件初始化
      this.showAddress = false;
      if (this.$refs.yz_showAddressShop) {
        this.$refs.yz_showAddressShop.init();
      }
      if (this.$refs.yz_showAddress) {
        this.$refs.yz_showAddress.init();
      }
      if (this.$refs.yz_addressList) {
        this.$refs.yz_addressList.init();
      }
    },
    vipPriceMethod(vip_price, total) {
      return (Number(vip_price) / Number(total)).toFixed(2);
    },
    setCityDeliveryCommunity() {
      this.cityDelivery_community = this.cityDelivery.community_setting.community_list.find(item => {
        return item.id == this.cityDelivery_community_id;
      });
      this.selectCommunityShow = false;
    },
    openCityDeliveryDay() {
      this.$refs.deliveryTime.setPopShow(true);
    },
    cityDeliveryDayConfirm(detail) {
      this.cityDelivery_deliveryTime = detail;
      this.handleBuy();
    },
    tolocation() {
      this.$router.push(this.fun.getUrl("o2oLocation_loc", {}, { tag: "suppligoodsOrde" }));
    },
    //初始化数据 distributionUserName
    initData() {
      let _globalParameter = JSON.parse(window.localStorage.getItem("globalParameter")) || {};
      this.vip_show = _globalParameter?.vip_show || false;
      this.hideDispatch = _globalParameter?.hide_dispatch || false;
      this.recharge_mobile = "";
      this.yz_lease_time = {
        days: 0,
        lease_term_id: ""
      };
      this.show_recharge_mobile = "";
      this.show_domain = false;
      this.shop_domain = "";
      this.clicktag = 0;
      this.good_clicktag = 0;
      this.default_deduction = 0;

      this.submit_active = true;
      //地址清空
      this.realname = "";
      this.mobile = "";
      this.local_life_mobile = '';
      this.address = "";

      this.linkinfo = {
        mobile: "",
        name: ""
      };
      this.oldOrder_data = [];
      this.order_data = [];
      this.defaultAddress = {};

      this.store_info = {};
      this.storeCarts = [];
      this.store_id = 0;
      this.selected = this.selected == 10 ? this.selected : 0;
      this.showAddress = false;
      this.goodsInfo = {};
      this.order = {};
      this.dispatch = [];

      this.getParams_status = false;
      this.myRealname = "";
      this.myIdcard = "";
      this.showMyinfo = false;
      this.showFrom = false;

      this.isRent = false;
      this.AgreementPay = "";
      this.checkList = [];
      this.isRightChoose = false;
      this.rentTime = [];
      this.rentFree = "";

      this.isOpenRight = false;
      this.agreement = false;
      this.agreementPay = false;
      this.agreementShow = false;
      this.agreementPayShow = false;
      this.agreeCon = {};
      this.note = [];

      // 优惠券
      this.popupCouponSpecs = false;
      this.coupon_size = 0;
      this.use_coupon_size = 0;
      this.checkCouponList = [];
      this.coupons = [];
      this.isShowCoupon = true;

      // 抵扣
      this.checkDeductionList = [];

      // 续费商品
      this.goods_id = "";
      this.isGetAgreementPay = false;

      currentAddId = "";
      this.currentAddress = {};

      _cart_ids = [];

      this.isOpenTeam = false;
      this.isJoinTeam = false;
      this.isCueCoupon = false;
      this.openCueCoupon = false;

      this.fileList1 = []; //相册
      this.isPhoto = false;

      this.defaultSelfCarry = "";
      this.form_data_id = "";
      this.for_serviceFee_status = false;
      this.service_fee = [];
      this.is_show_store_delivery = false;
      this.is_open_store_delivery = false;
      this.locationName = "";
      this.district_id = this.$route.params.district_id || 0;
      this.deliveryScopeShow = false;

      this.pre_order_url = ""; // 预下单的url
      this.order_url = ""; // 提交订单的url
      this.order_other_json = {}; // 每种类型多余的参数
      this.isCartsOrder = false;
      this.local_life.need_mobile = false;
      this.isTaxGoods = false;

      this.phone_bill_pro_goods = false;
      // 电费充值
      this.electricity = this.$route.query.electricity == "electricity" ? true : false;
      this.eleUser = [];
      this.ele_no_showAdress = false;
      this.plugin_setting = localStorage.getItem("plugin_setting") ? JSON.parse(localStorage.getItem("plugin_setting")) : "";
    },

    // 处理query数据
    async handleQueryData() {
      // 接收tag参数
      this.root_tag = this.$route.query.tag;
      console.log("this.root_tag", this.root_tag);
      if (this.fun.isTextEmpty(this.root_tag)) {
        // 为空跳回
        this.$router.go(-1);
        return;
      }

      // 云库存预下单
      if (this.$route.query.fromStock) {
        this.fromStock = this.$route.query.fromStock;
      }

      // 话费充值
      if (this.$route.query.mobile) {
        this.phone_bill_pro_goods = true;
        this.recharge_mobile = this.$route.query.mobile;
      }

      //油卡充值
      if (this.$route.query.oil_mobile && this.$route.query.oil_account) {
        this.oil_mobile = this.$route.query.oil_mobile;
        this.oil_account = this.$route.query.oil_account;
      }

      // 聚合cps商品预下单
      if (this.$route.query.cpstype) {
        this.cpsType = this.$route.query.cpstype;
      }
      if (this.$route.query.iscps) {
        this.is_cps = true;
      }

      // 商品相册
      if (JSON.parse(window.localStorage.getItem("globalParameter")) && JSON.parse(window.localStorage.getItem("globalParameter")).is_open_photo_order == "1" && this.root_tag == TAG_ACTION_BUY) {
        //需求：商城商品、供应商商品立即购买和门店商品下单才能使用相册上传模块，且一个下单的商品id（新需求去掉购物车，不能使用相册）
        this.isPhoto = true; //开启相册上传模块
        this.$nextTick(() => {
          this.$refs.yzUploader.initData();
        });
        this.setPhotoNum();
      }

      // 拼团
      this.isOpenTeam = !this.fun.isTextEmpty(this.$route.query.level_id); //是否为一键开团
      this.isJoinTeam = !this.fun.isTextEmpty(this.$route.query.team_id); //是否为去参团

      // 自提点
      let fromChange = this.$route.params.changeSelfCarry ? JSON.parse(this.$route.params.changeSelfCarry) : this.$route.query.changeSelfCarry ? JSON.parse(this.$route.query.changeSelfCarry) : null;
      if (fromChange) {
        //从更换自提点列表页面选择后返回 或者 社群团购结算进入tag=communityBuy
        if (this.$route.query.dispatch_id == 12) {
          // 门店自提点
          this.o2oSelfCarry = fromChange;
        } else {
          this.defaultSelfCarry = fromChange;
        }
      }

      if (JSON.parse(window.localStorage.getItem("globalParameter")) && JSON.parse(window.localStorage.getItem("globalParameter")).order_locate == true) {
        this.orderLocationObj = await this.getCurrentOrderLocation();
      }

      // 设置主要参数
      _goodsId = this.$route.query.goodsId || "";
      _optionsId = this.$route.query.optionsId || 0;
      _total = this.$route.query.total || 1;

      //蛋糕叔叔定位的城市名称
      if (this.root_tag === "cake") {
        let cakeDetail = JSON.parse(window.localStorage.getItem("cakeStoreDetail"));
        if (cakeDetail) {
          this.shopId = cakeDetail.shop_id;
          this.shopName = cakeDetail.shop_name;
          this.shopDetail = cakeDetail.address;
        }
        this.cakeCity = this.$route.query.city;
        this.handleBuy();
        this.fun
          .getLocation("正在定位")
          .then(res => {
            let ares = this.fun.bd_encrypt(res.point.lng, res.point.lat);
            this.cakeLng = ares.lng;
            this.cakeLat = ares.lat;
          })
          .catch(err => {
            // this.$router.go(-1);
            console.log(err);
          });
        return;
      }
      let yz_basic_info = JSON.parse(window.localStorage.getItem("yz_basic_info")) || {};
      if (yz_basic_info.plugin_setting && yz_basic_info.plugin_setting.lease_toy) {
        this.isRentSetting = yz_basic_info.plugin_setting.lease_toy.is_hide_price_and_deposit;
      }
      if (yz_basic_info?.globalParameter?.coffee_machine_open_state === 1) {
        this.coffee_machine_open_state = true;
        this.getCoffeeMachineGoodsId();
      }

      if (this.$route.query.hasOwnProperty("cart_ids") && this.$route.query.cart_ids && typeof this.$route.query.cart_ids == "string") {
        // 购物车下单
        _cart_ids = this.$route.query.cart_ids.split(",");
        if (this.fun.isTextEmpty(_cart_ids)) {
          // 为空跳回
          this.$router.go(-1);
          return;
        }
      }

      if (this.root_tag == TAG_ACTION_BUY || this.root_tag == "activity" || this.root_tag == "cps" || this.root_tag == "store" || this.root_tag == "reserve") {
        // this.store_id要根据情况赋值
        if (this.$route.query.hasOwnProperty("store_id") && this.$route.query.store_id) {
          // 门店购物车下单
          this.store_id = this.$route.query.store_id;
          let storeTable = JSON.parse(sessionStorage.getItem("storeTable")) || null; //门店扫码餐桌信息
          if (storeTable && storeTable.table_store == this.store_id) {
            this.storeTable = storeTable;
          }
        }
      }
      if (this.root_tag != "POrder" && this.root_tag != "store") {
        //第请求接口获取配送方式后，取默认第一个的dispatch_type_id再请求预下单接口;  挂单POrder走固定的配送方式
        this.getDispatchMethod();
      } else {
        this.handleBuy();
      }
    },
    getCoffeeMachineGoodsId() {
      if (this.root_tag == -1 || this.root_tag == -2 || this.root_tag == "coffee") {
        let arr = _goodsId || this.$route.query.cart_ids;
        let json;
        if (arr.length > 1) {
          json = { goods_ids: arr.split(",") };
        } else {
          json = { goods_ids: arr };
        }
        if (this.root_tag == -1) {
          json.create_type = 2;
        } else {
          json.create_type = 1;
        }
        $http.post("plugin.coffee-machine.frontend.buyer.getCoffeeMachineGoodsId", json, "loading").then(response => {
          if (response.result == 1) {
            this.coffeeDay = response.data.day;
            this.coffee_goods_ids = response.data.goods_ids;
          } else {
            this.$toast(response.msg);
          }
        });
      }
    },
    // handleExchangeCode(){
    //   let json = {  goods_id: _goodsId ? _goodsId.toString() : ""};
    //   if(this.$route.query.device_id){
    //     json.device_id = this.$route.query.device_id;
    //   }
    //   $http
    //   .post("memberCart.dispatch-type.index", json,'').then(res=>{
    //     console.log(res);
    //   })
    // },
    // 获取配送方式
    getDispatchMethod(cart_ids) {
      if (this.root_tag == "communityBuy") {
        // 社区团购直接设置，走配送方式接口返回为空，前端自定义，自提点不可更换
        this.dispatch = [{ dispatch_type_id: 8, name: "自提点" }];
        this.selected = 8;
        this.handleBuy();
        return;
      }
      // goods_ids 商品id字符串，多个用逗号分割; cart_ids购物车id
      // nonsupport 填写不需要的配送方式id
      let json = {
        goods_id: _goodsId ? _goodsId.toString() : "",
        cart_ids: this.$route.query.cart_ids || cart_ids,
        store_id: this.$route.query.store_id || this.$route.query.groupStoreID,
        model: ""
      };
      if (this.root_tag == "store") {
        json.model = "store";
      }
      if (this.root_tag == "-10") {
        json.model = "packFixedPrice";
      }

      if (this.isOpenTeam || this.isJoinTeam) {
        json.nonsupport = ["15"]; //不支持商城自提
      }

      if (this.root_tag == "warehouse" && this.$route.query.goods) {
        let _goods_ids = [];
        JSON.parse(this.$route.query.goods).forEach(item => {
          _goods_ids.push(item.goods_id);
        });
        json.goods_ids = JSON.stringify(_goods_ids);
      }

      if (this.root_tag == "agency-th" && this.$route.query.goods) {
        let _goods_ids = [];
        JSON.parse(this.$route.query.goods).forEach(item => {
          _goods_ids.push(item.goods_id);
        });
        json.goods_ids = JSON.stringify(_goods_ids);
        json.agency_stock_take = 1;
      }

      if (this.root_tag == "packagBuy" || this.root_tag == "giftBuy") {
        json.goods_ids = this.$route.query.goods_ids;
      }
      if (this.$route.query.device_id) {
        json.device_id = this.$route.query.device_id;
      }
      let url = "memberCart.dispatch-type.index";
      if (this.root_tag == "exchange_code") {
        //兑换码
        url = "plugin.exchange-code.api.dispatch.index";
        json = {
          goods_ids: _goodsId ? _goodsId.toString() : ""
        };
      }
      $http
        .post(url, json,'.')
        .then(
          response => {
            if (response.result === 1) {
              if (this.$route.params.debtId) {
                this.dispatch = [{ dispatch_type_id: 1, name: "快递" }];
              } else {
                this.dispatch = response.data || [];
              }
              if (this.selected == 10) {
                console.log(this.selected, "供应商导航");
              } else {
                this.selected = this.dispatch && this.dispatch.length > 0 ? this.dispatch[0].dispatch_type_id : 0; //默认第一
                // 连锁店指定默认配送方式
                if (this.$route.query.get_type) {
                  // console.log('连锁店指定默认配送方式',this.$route.query.get_type)
                  if (this.$route.query.get_type == 1) {
                    this.selected = 2;
                  } else if (this.$route.query.get_type == 2) {
                    this.selected = 3;
                  } else if (this.$route.query.get_type == 3) {
                    this.selected = 1;
                  }
                }
                if (this.selected == 11) {
                  // 当配送方式第一个或者只有同城配送时，请求
                  this.getDeliverySetting();
                }
              }
              this.dispatch.forEach(items => {
                if (items.dispatch_type_id == 8 && this.$route.query.dispatch_id == 8) {
                  // 从自提点列表回来
                  if (this.defaultSelfCarry && this.defaultSelfCarry.id) {
                    this.selected = 8;
                  }
                } else if (this.$route.query.dispatch_id == 12) {
                  //从门店自提点列表选择后来
                  if (this.o2oSelfCarry && this.o2oSelfCarry.id) {
                    this.selected = 12;
                  }
                }
              });
              if (this.root_tag == "store") {
                this.getStoreCartBuy(this.storeCarts);
              } else {
                this.handleBuy();
              }
            } else {
              Toast(response.msg);
            }
          },
          response => {
            console.log(response);
          }
        )
        .catch(err => {
          console.log(err);
        });
    },
    // 判断类型处理预下单方式
    handleBuy(is_again) {
      // is_again判断是否重新请求数据  选择地址后是1   优惠券或者抵扣是2
      switch (this.root_tag) {
        case TAG_ACTION_BUY:
        case "appointment_goods":
        case "yun_sign_goods":
        case "yun_contract_lock_goods":
        case "yunqian_api":
        case "activity":
        case "cps":
        case "channel_buy": //渠道商立即购买
        case "blindBox":
        case "fromExchange":
        case "auction":
        case "zhpGroup":
        case "o2oDeposit":
          // 通常是单个商品的预下单
          if (!is_again) {
            if (this.$route.query.store_id) {
              // 门店拓客  门店预约
              this.initStore("is_activity");
            } else if (this.$route.query.groupStoreID) {
              //门店拼团
              this.initStore();
            }
            // 只为了获取配送方式
          } else if (this.root_tag == "fromExchange" && is_again === "2") {
            //会员中心-兑换中心-去兑换（商城商品）
            this.getDataActionBuy(0);
            return;
          }
          this.getDataActionBuy(); // 直接购买
          break;
        case TAG_ACTION_CART: // 商城购物车结算
        case "-10": // 一口价
        case "communityBuy": // 社区团购
        case "channel": // channel渠道商订货购物车结算
        case "channel_Replenishment":
        case "channel_TCOrder":
        case "packagBuy":
        case "giftBuy":
        case "purchasingCenter":
        case "suppThreeCart":
          this.isCartsOrder = true;
          // 通常是购物车的预下单
          if (this.root_tag == "packagBuy" || this.root_tag == "giftBuy") {
            // 套餐购买 使用params不能刷新
            if (!is_again) {
              _packagJson = this.$route.params.packagJson||this.$route.query.packagJson;
              if (this.fun.isTextEmpty(_packagJson)) {
                // 为空跳回
                this.$router.go(-1);
                return;
              }
            }
          }
          this.getDataActionCart();
          break;
        case "store":
          this.isCartsOrder = true;
          if (this.$route.query.energy_machine_id) {
            // 能量仓---门店商品直接购买
            this.getDataActionBuy(); // 直接购买
            return;
          }
          if (!is_again) {
            // 门店购物车购买
            if (this.$route.query.isCash === 1) {
              // 门店过期商品下单
              this.getCashGood();
            } else {
              this.initStore();
            }
          } else {
            this.getDataActionStoreCart(); // 门店结算
          }
          break;
        case "yzlease":
          // 租赁购物车或租赁预下单
          this.isRent = true;
          this.getDataActionBuy(); // 直接购买
          break;
        case "rentCartBuy":
        case "rentBuy":
          if (!is_again) {
            // 租赁购物车或租赁预下单
            this.currentIndex = "999";
            this.isRent = true;

            this.getRentDataActionCart([], []);
            this.getRentTimeList();
            this.judgeIsRight();
          } else {
            this.rentGoodBuy();
          }
          break;
        case "POrder":
          //挂单商品
          this.getPendingOrder_type(); //批发区下单页类型判断,即导航栏判断
          break;
        default:
          this.getDataActionBuy(); // 直接购买
      }
    },
    // 处理单个商品的预下单 设置预下单链接  提交订单链接  类型额外的数据
    handleDataActionBuyUrl(json, tag) {
      console.log(1111,this.root_tag,'root_tag==');
      if (this.isRent) {
        if (this.root_tag == "yzlease") {
          this.pre_order_url = "plugin.yz-supply-lease.api.goods-buy.index";
          this.order_url = "plugin.yz-supply-lease.api.create.index";
          this.order_other_json = {
            lease_tenancy_terms_id: this.yz_lease_time.lease_term_id,
            nums_day: this.yz_lease_time.days
          };
        } else {
          // 租赁
          this.order_url = "plugin.lease-toy.api.order.create";
        }
      } else if (this.isPhoto) {
        this.order_url = "plugin.photo-order.api.create";
      } else if (this.root_tag == "coffee") {
        this.pre_order_url = "plugin.coffee-machine.frontend.order.goods-buy.index";
        this.order_url = "plugin.coffee-machine.frontend.order.create.index";
        this.order_other_json = {
          coffee_pre_order_sn: this.$route.query.coffee_pre_order_sn
        };
      }else if(this.root_tag == 'local_life'){
        this.hideDispatch = true;
        this.order_other_json = {
          mobile:this.local_life_mobile
        }
      }else if (this.root_tag == "appointment_goods") {
        this.order_url = "plugin.appointment.frontend.order.create";
        if (this.$route.query.exchange_code_id) {
          //兑换码日志id
          this.pre_order_url = "plugin.exchange-code.api.goods-buy";
          this.order_other_json = {
            exchange_code_id: this.$route.query.exchange_code_id
          };
        }
      } else if (this.root_tag == "yun_sign_goods") {
        this.order_url = "plugin.yun-sign.frontend.order.create";
      } else if (this.root_tag == "yun_contract_lock_goods") {
        this.order_url = "plugin.yun-contract-lock.frontend.order.create";
      } else if (this.root_tag == "yunqian_api") {
        this.order_url = "plugin.yunqian-api.frontend.order.create";
      } else if (this.root_tag == "activity") {
        this.order_url = "plugin.activity-apply.api.create";
      } else if (this.root_tag == "store_projects_goods") {
        this.order_url = "plugin.store-projects.frontend.order.create";
        if (this.$route.query.exchange_code_id) {
          //兑换码日志id
          this.pre_order_url = "plugin.exchange-code.api.goods-buy";
          this.order_other_json = {
            exchange_code_id: this.$route.query.exchange_code_id
          };
        }
      } else if (this.fromStock == 1) {
        //云库存立即购买
        this.pre_order_url = "plugin.agency.api.goods-buy.index";
        if (this.$route.query.is_retail) {
          this.order_other_json = {
            is_retail: true, //云库存零售传值
            salesman_uid: (this.$refs.agencySaleman && this.$refs.agencySaleman.self_member_id) || "" //销售员id
          };
        }
        this.order_url = "plugin.agency.api.create.index";
      } else if (this.isOpenTeam || this.isJoinTeam) {
        // 拼团
        this.order_other_json = {
          option_level_id: this.$route.query.option_level_id //规格层级id
        };
        let PLU = "fight-groups";
        if (this.$route.query.plug && this.$route.query.plug == "ywm") PLU = "ywm-fight-groups";

        if (this.isOpenTeam) {
          this.order_other_json.level_id = this.$route.query.level_id; //一键开团 拼团层级id
          this.pre_order_url = `plugin.${PLU}.frontend.controllers.team.pre-open-team`;
        } else if (this.isJoinTeam) {
          this.order_other_json.team_id = this.$route.query.team_id; //一键参团 拼团层级id
          this.pre_order_url = `plugin.${PLU}.frontend.controllers.team.pre-join-team`;
        }

        this.order_url = `plugin.${PLU}.frontend.controllers.create.index`;

        if (this.$route.query.groupStoreID) {
          this.order_other_json.store_id = this.$route.query.groupStoreID; //门店id
          //门店拼团
          this.pre_order_url = this.isOpenTeam ? "plugin.fight-groups.frontend.store.frontend-team.pre-open-team" : "plugin.fight-groups.frontend.store.frontend-team.pre-join-team";

          this.order_url = "plugin.fight-groups.frontend.store.create.index";
        }
      } else if (this.$route.query.orderType == "groupBuy_open" || this.$route.query.orderType == "groupBuy_join") {
        //拼购商品开团或参团
        this.order_other_json = {
          at_id: this.$route.query.at_id, //活动ID
          leader_id: this.$route.query.leader_id || 0 //团长ID
        };
        delete json.option_id;
        this.pre_order_url = this.$route.query.orderType == "groupBuy_open" ? "plugin.together-purchase.api.team.preOpenTeam" : "plugin.together-purchase.api.team.preJoinTeam";

        this.order_url = "plugin.together-purchase.api.create.index";
      } else if (this.$route.query.orderType == "grabGroup_open" || this.$route.query.orderType == "grabGroup_join") {
        //抢团开团或参团
        this.order_other_json = {
          at_id: this.$route.query.at_id, //活动ID
          leader_id: this.$route.query.leader_id || 0, //团长ID
          snatch_option_id: _optionsId
        };
        json.option_id = 0;
        this.pre_order_url = this.$route.query.orderType == "grabGroup_open" ? "plugin.snatch-regiment.api.team.preOpenTeam" : "plugin.snatch-regiment.api.team.preJoinTeam";

        this.order_url = "plugin.snatch-regiment.api.create.index";
      } else if (this.$route.query.tag == "POrder") {
        //挂单商品
        this.order_other_json = {
          mark: this.$route.query.mark, //规格层级id
          pending_order_type: this.selected //批发订单使用类型
        };
        this.pre_order_url = "plugin.pending-order.frontend.goods-buy.index";

        this.order_url = "plugin.pending-order.frontend.create.index";
      } else if (this.$route.query.tag == "o2oDeposit") {
        //门店定金阶梯团下单（非门店的活动走商城普通商品立即购买下单流程）【#82681】
        this.order_other_json = {
          store_id: this.$route.query.store_id || "" //门店ID
        };
        this.pre_order_url = "plugin.deposit-ladder.frontend.store.activity-buy";
      } else if (this.$route.query.store_id) {
        if (this.$route.query.tag == "reserve") {
          // 门店预约
          this.order_other_json = {
            date_id: this.$route.query.date_id, //日期ID
            store_id: this.$route.query.store_id || 0, //门店ID
            goods_id: _goodsId
          };
          if (tag === "order") {
            this.order_other_json.mobile = this.reservePhone;
            this.order_other_json.realname = this.reserveName;
          }
          this.pre_order_url = "plugin.store-reserve.frontend.GoodsBuy.index";

          this.order_url = "plugin.store-reserve.frontend.create.index";
        } else {
          //门店拓客
          this.order_other_json = {
            store_id: this.$route.query.store_id || 0 //门店ID
          };
          if (tag === "order") {
            this.order_other_json.mobile = this.linkinfo.mobile;
            this.order_other_json.realname = this.linkinfo.name;
            this.order_other_json.cart_ids = [];
          }
          this.pre_order_url = "plugin.store-cashier.frontend.store.goods-buy";
          if (this.$route.query.energy_machine_id) {
            // 能量仓---门店商品更换路由
            this.pre_order_url = "plugin.energy-machine.frontend.store-goods-buy.index";
          }
          // 走门店下单
        }
      } else if (this.$route.query.tag == "blindBox") {
        this.order_other_json = {
          activity_id: this.$route.query.at_id, //活动ID
          goods_id: _goodsId
        };
        this.pre_order_url = "plugin.blind-box.api.buy";

        this.order_url = "plugin.blind-box.api.create";
      } else if (this.$route.query.tag == "channel_buy") {
        //渠道商立即购买
        this.order_other_json = {
          channel_type: "2" //2进货
        };
        this.pre_order_url = "plugin.channel.frontend.replenish-goods-buy.index";

        this.order_url = "plugin.channel.frontend.replenish-create.index";
      } else if (this.root_tag == "fromExchange") {
        //会员中心-兑换中心
        if (this.$route.query.store_id && this.$route.query.store_id !== undefined) {
          this.order_other_json.store_id = this.$route.query.store_id;
          this.pre_order_url = "plugin.store-cashier.frontend.store.exchange-center";
        } else {
          this.pre_order_url = "coupon.exchange-center.exchange-buy";
        }
      } else if (this.$route.query.orderType == "newRetail") {
        //新零售 0-自由零售 1-成为代理商订单 2-自由发货 3-线上零售 4-进货订单 5-销售代理套餐订单
        this.order_other_json = {
          retail_state: this.$route.query.retail_state,
          level_id: this.$route.query.NRLevelId || 0, //等级id
          sales_id: this.$route.query.sales_id || 0 //记录id
        };
        // if (this.$route.query.retail_state == 2) {
        //   this.order_other_json.goods = JSON.parse(this.$route.query.goods) || []; // 自由发货
        // }
        this.pre_order_url = this.newRetailApi(this.$route.query.retail_state);

        if (this.$route.query.retail_state == 0) {
          this.order_url = "plugin.new-retail.frontend.create.ordinary"; // 自由发货
        } else {
          this.order_url = "plugin.new-retail.frontend.create.index";
        }
      } else if (this.root_tag == "auction") {
        //拍卖商品
        this.order_other_json = {
          fixed_price: this.$route.query.fixed_price,
          auction_sn: this.$route.query.auction_sn
        };
        this.pre_order_url = "plugin.auction.api.goods-buy";

        this.order_url = "plugin.auction.api.order-create";
      } else if (this.root_tag == "zhpGroup") {
        //珍惠拼参团
        this.order_other_json = {
          activity_id: this.$route.query.activity_id,
          option_id: _optionsId
        };
        this.pre_order_url = "plugin.zhp-group-lottery.frontend.goods.get-goods-Info";

        this.order_url = "plugin.zhp-group-lottery.frontend.order.index";
      } else if (this.root_tag == "group-work") {
        this.order_other_json = {
          alliance_detail_id: this.$route.query.alliance_detail_id,
          activity_option_id: this.$route.query.activity_option_id
        };
        this.pre_order_url = "plugin.group-work.frontend.modules.order.controllers.buy.index";
        this.order_url = "plugin.group-work.frontend.modules.order.controllers.create.index";
      } else if (this.root_tag == "warehouse") {
        this.order_other_json = {
          goods: this.$route.query.goods
        };
        this.pre_order_url = "plugin.warehouse.frontend.controllers.takeDelivery.goods-buy";
        this.order_url = "plugin.warehouse.frontend.controllers.takeDelivery.order-create";
      } else if (this.root_tag == "agency-th") {
        this.order_other_json = {
          goods: this.$route.query.goods,
          agency_stock_take: 1
        };
        this.pre_order_url = "plugin.agency.api.stock-take.index";
        this.order_url = "plugin.agency.api.create-take.index";
      } else if (this.root_tag == "timeAppoint") {
        this.order_url = "plugin.reserve-simple.frontend.order.create";
        this.reserve_order.service_id = this.$route.query.reserveItem ? this.$route.query.reserveItem.service_id : "";
        this.reserve_order.obj_id = this.$route.query.reserveItem ? this.$route.query.reserveItem.id : "";
        this.reserve_order.begin_time = this.$route.query.reserveDate;
        this.order_other_json = {
          reserve_order: this.reserve_order
        };
      } else if (this.$route.params.debtId) {
        this.order_other_json = {
          debtor_id: this.$route.params.debtId
        };
        this.pre_order_url = "plugin.debt-shop.frontend.goods-buy";
        this.order_url = "plugin.debt-shop.frontend.create";
      } else if (this.$route.query.name == "newBlindBox") {
        this.order_other_json = {
          new_blind_box: {
            select_goods: JSON.parse(this.$route.query.select_goods),
            activity_id: this.$route.query.activity_id
          }
        };
      } else if (this.root_tag == "sign_buy") {
        //套餐
        this.order_other_json = {
          goods: this.$route.params.goods,
          package_id: this.$route.query.package_id
        };
        this.pre_order_url = "plugin.sign-buy.frontend.package.pre-buy";
        this.order_url = "plugin.sign-buy.frontend.package.buy";
      } else if (this.root_tag == "tourAround") {
        //周边游新的支付
        this.order_url = "plugin.travel-around.frontend.order.createOrder";
      } else if (this.root_tag == "vending_machine") {
        this.hideDispatch = true;
        this.order_other_json.automat_machine_id = this.$route.query.machineId;
        this.pre_order_url = "plugin.automat.frontend.goods-buy.index";
        this.order_url = "plugin.automat.frontend.create.index";
      } else if (this.root_tag === "cake") {
        //蛋糕叔叔的格外参数
        this.order_other_json = {
          city_cake: this.cakeCity,
          delivery_amount: this.deliveryAmount,
          cake_ship_type: this.cakeShipType
        };
      } else if (this.root_tag == "exchange_code") {
        //兑换码
        let _goods = JSON.parse(this.$route.query.goods);
        let total = 0;
        _goods.forEach(item => {
          total += item.total;
        });
        this.order_other_json = {
          goods: JSON.stringify(_goods),
          total,
          exchange_code_id: this.$route.query.exchange_code_id
        };
        this.pre_order_url = "plugin.exchange-code.api.cart.index";
        this.order_url = "plugin.exchange-code.api.create";
      } else if (this.root_tag == "stock_service") {
        //存货服务
        this.order_other_json = {
          take_way: this.$route.query.take_way,
          stock_token: this.$route.query.stock_token,
          take_type: this.$route.query.take_type,
          goods: `[{"goods_id":${this.$route.query.goodsId},"total":${this.$route.query.total},"option_id": ${this.$route.query.option_id}}]`
        };
        this.pre_order_url = "plugin.stock-service.frontend.controllers.goods-buy";
        this.order_url = "plugin.stock-service.frontend.controllers.order-create";
      } else if (this.root_tag == "consignment") {
        //寄售商品
        this.order_other_json = {
          member_voucher_id: this.$route.query.VoID
        };
        this.pre_order_url = "plugin.consignment.frontend.controllers.order.goods-buy";
        this.order_url = "plugin.consignment.frontend.controllers.order.create";
      } else if (this.root_tag === "collection-center") {
        //数字藏品
        this.order_url = "plugin.collection-center.frontend.controllers.order.create";
        this.pre_order_url = "plugin.collection-center.frontend.controllers.order.goods-buy";
      } else if (this.root_tag === "custom") {
        //定制团格外参数
        this.order_other_json = {
          customized_group_id: this.$route.query.customized_group_id
        };
        this.order_url = "plugin.customized-group.frontend.controllers.create.index";
        this.pre_order_url = "plugin.customized-group.frontend.controllers.goods-buy.index";
      } else if (this.root_tag === "distribution_coupon") {
        this.order_other_json = {
          distribution_coupon_ids: JSON.stringify(this.distribution_coupon_ids)
        };
        this.pre_order_url = "plugin.distribution-coupon.api.goods-buy";
        this.order_url = "plugin.distribution-coupon.api.create";
      } else if (this.root_tag == "purchasingCenterNow") {
        // 进货中心购物车立即购买
        this.pre_order_url = "plugin.gradevin-stock.frontend.controllers.goods-buy.index";
        this.order_url = "plugin.gradevin-stock.frontend.controllers.create.index";
      } else if (this.root_tag == 'oil_order'){
        this.order_other_json = {
          litre: this.$route.query.litre,
          plate_num: this.$route.query.plate_num,
          goods_id: this.$route.query.goodsId,
          oil_gun: this.$route.query.oil_gun,
          sn: this.$route.query.sn,
          source: this.$route.query.source,
          amt:this.$route.query.amt,
        };
        this.pre_order_url = "plugin.store-oil-station.frontend.buy";
        this.order_url = "plugin.store-oil-station.frontend.order-create";
      } else if (this.root_tag == "new_auction"){
        this.pre_order_url = "plugin.new-auction.frontend.pick-goods-buy";
        this.order_url = "plugin.new-auction.frontend.pick-create";
        this.order_other_json = {
          new_auction_id: this.$route.params.new_auction_id,
          new_auction_pick_num: this.$route.params.new_auction_pick_num
        };
      } else if (this.root_tag == "new_auction_mentioned"){
        this.pre_order_url = "plugin.new-auction.frontend.extra-goods-buy";
        this.order_url = "plugin.new-auction.frontend.extra-create";
        this.order_other_json = {
          new_auction_activity_id: this.$route.params.new_auction_activity_id,
          new_auction_pick_num: this.$route.params.new_auction_pick_num
        };
      } else if (this.root_tag == 'apply'){
        // 赛事报名立即购买
        this.order_other_json = {
          apply_id:Number(this.$route.query.applyId),
        };
        this.pre_order_url = "plugin.event-registration.api.goods.goods-buy";
        this.order_url = "plugin.event-registration.api.order.create";
      }else if (this.root_tag == 'map-marker') {
        this.pre_order_url = "plugin.map-marker.frontend.controllers.order.goods-buy";
        this.order_url = "plugin.map-marker.frontend.controllers.order.create";

      } else if (this.root_tag == 'check_in_rebate') {
        //补卡商品
        this.pre_order_url = "plugin.check-in-rebate.frontend.goods-buy";
        this.order_url = "plugin.check-in-rebate.frontend.create";
      }
      if (this.$route.query.electricity == "electricity") {
        this.order_other_json.account_id = this.$route.query.account_id;
      }

      if (this.$route.query.merchant_meeting) {
        //线下招商会商品下单，多传一个活动id
        this.order_other_json.merchant_meeting = this.$route.query.merchant_meeting;
      }

      if (this.$route.query.share_uid) this.order_other_json.share_uid = this.$route.query.share_uid;

      if (!this.pre_order_url) {
        this.pre_order_url = "order.goods-buy";
        if (this.$route.query.root_tag == "exchange_code") {
          this.order_url = "plugin.yz-supply-camilo-resources.frontend.order.create.index";
          this.order_other_json = {
            exchange_code_id: this.$route.query.exchange_code_id
          };
        }
      }
      if (this.$route.query.device_id) {
        // 如果有device_id的ktv酒柜的设备id
        this.order_other_json = {
          device_id: this.$route.query.device_id
        };
        if (this.$route.query.cargo_road_id) {
          this.order_other_json.cargo_road_id = this.$route.query.cargo_road_id;
        }
        if (this.$route.query.is_gradevin_sing) {
          this.order_other_json.is_gradevin_sing = this.$route.query.is_gradevin_sing;
        }
      }

      if (!this.order_url) {
        if (this.is_cps) {
          // 如果是聚合cps的商品走立即购买换这个接口
          this.order_url = "plugin.aggregation-cps.api.create-order";
        } else {
          this.order_url = "order.create";
        }
      }
      if (this.default_deduction != 0) {
        // 默认积分抵扣
        this.order_other_json.no_deduction_ids = this.default_deduction;
      }

      //同城配送
      if (this.cityDelivery && this.cityDelivery.future_state == 1) {
        if (this.cityDelivery_deliveryTime.start_time && this.cityDelivery_deliveryTime.end_time) {
          json.expect_start_time = this.cityDelivery_deliveryTime.start_time;
          json.expect_end_time = this.cityDelivery_deliveryTime.end_time;
        }
      }
      if (this.$route.query.apd_special_order_id) {
        this.order_other_json = {
          apd_special_order_id: this.$route.query.apd_special_order_id
        };
      }
      if (this.selected == "16") {
        // 门店自提点
        json.ecp_code = this.extra_info.ecp_code;
        json.ecp_number = this.extra_info.ecp_number;
      }

      return Object.assign(json, this.order_other_json);
    },
    // 处理购物车的预下单 设置预下单链接  提交订单链接  类型额外的数据
    handleDataActionCartUrl(json, tag) {
      if (this.root_tag == "-10") {
        // 一口价下单
        this.pre_order_url = "plugin.pack-fixed-price.api.cart-buy.index";
        if (tag === "order") {
          let fixedArr = this.$route.query.cart_ids.split(",");
          this.order_other_json.cart_ids = JSON.stringify(fixedArr);
        }

        this.order_url = "plugin.pack-fixed-price.api.create.index";
      } else if (this.root_tag == "communityBuy") {
        //社区团购
        this.pre_order_url = "plugin.package-deliver.frontend.cartBuy.index";
        this.order_other_json = {
          dispatch_type_id: 8,
          package_deliver_id: this.$route.query.package_deliver_id,
          group_id: this.$route.query.group_id
        };

        this.order_url = "plugin.package-deliver.frontend.create.index";
      } else if (this.root_tag == "channel_TCOrder") {
        // 渠道商订货购物车结算
        // 2:订货 1:补货
        this.order_other_json.channel_type = "2";
        if (tag === "order") {
          this.order_other_json.address = {};
        }
        this.pre_order_url = "plugin.channel.frontend.replenish-cart-buy.index";

        this.order_url = "plugin.channel.frontend.replenish-create.index";
      } else if (this.root_tag == "channel" || this.root_tag == "channel_Replenishment") {
        // 2:订货 1:补货
        this.order_other_json.channel_type = this.root_tag == "channel_Replenishment" ? "1" : "2";
        this.order_other_json.order_id = this.$route.query.order_id;
        if (tag === "order") {
          this.order_other_json.address = {};
        }
        this.pre_order_url = "plugin.channel.frontend.cart-buy.index";

        this.order_url = "plugin.channel.frontend.create.index";
      } else if (this.root_tag == "packagBuy") {
        this.order_other_json.package_id = _packagJson.package_id;
        this.order_other_json.goods = JSON.stringify(_packagJson.goods_list);
        // 套餐购买
        this.pre_order_url = "plugin.goods-package.frontend.package.package-buy.index";
        this.order_url = "plugin.goods-package.frontend.package.create.index";
      } else if (this.root_tag == "giftBuy") {
        this.order_other_json.package_id = _packagJson.package_id;
        this.order_other_json.goods = JSON.stringify(_packagJson.goods_list);
        // 礼包购买
        this.pre_order_url = "plugin.goods-package.frontend.package.package-buy.index";
        this.order_url = "plugin.goods-package.frontend.package.package-create.index";
      } else if (this.fromStock == 1) {
        //云库存订货购物车结算
        this.pre_order_url = "plugin.agency.api.cart-buy.index";
        // if (this.$route.query.is_retail) {
        //   this.order_other_json = {
        //     is_retail: true, //云库存零售传值
        //     salesman_uid: (this.$refs.agencySaleman && this.$refs.agencySaleman.self_member_id) || "" //销售员id
        //   };
        // }
        this.order_url = "plugin.agency.api.create.index";
      } else if (this.root_tag == "purchasingCenter") {
        // 进货中心购物车结算
        this.pre_order_url = "plugin.gradevin-stock.frontend.controllers.cart-buy.index";
        this.order_url = "plugin.gradevin-stock.frontend.controllers.create.index";
        this.order_other_json.cart_ids = _cart_ids;
      } else if (this.root_tag == "suppThreeCart") {
        // 供应商首页样式三-购物车下单
        this.order_url = "plugin.supplier-shop-three.frontend.create.index";
        this.pre_order_url = "plugin.supplier-shop-three.frontend.cart-buy.index";
        this.order_other_json.cart_ids = _cart_ids;
      }

      if (tag === "order" && this.root_tag != "-10" && this.root_tag != "packagBuy" && this.root_tag != "giftBuy") {
        // 购物车下单需要购物车id是数组
        this.order_other_json.cart_ids = JSON.stringify(_cart_ids);
      }

      if (!this.pre_order_url) {
        this.pre_order_url = "order.cart-buy";
      }

      if (!this.order_url) {
        this.order_url = "order.create";
        if (this.$route.query.exchange_code_id) {
          //兑换码日志id
          this.pre_order_url = "plugin.exchange-code.api.goods-buy";
          this.order_other_json = {
            exchange_code_id: this.$route.query.exchange_code_id
          };
        }
      }

      if (this.default_deduction != 0) {
        // 默认积分抵扣
        this.order_other_json.no_deduction_ids = this.default_deduction;
      }
      return Object.assign(json, this.order_other_json);
    },

    newRetailApi(states) {
      let state = Number(states);
      //新零售 0-自由零售 1-成为代理商订单 2-自由发货 3-线上零售 4-进货订单 5-销售代理套餐订单c
      if (state == 0) {
        return "plugin.new-retail.frontend.order.ordinaryPay";
      } else if (state == 1) {
        return "plugin.new-retail.frontend.order.purchaseRetailGoods";
      } else if (state == 2) {
        return "plugin.new-retail.frontend.order.freeSend";
      } else if (state == 3) {
        return "plugin.new-retail.frontend.order.retailCodePay";
      } else if (state == 4) {
        return "plugin.new-retail.frontend.order.purchaseStock";
      } else if (state == 5) {
        return "plugin.new-retail.frontend.order.retailCodePay";
      }
    },
    setPhotoNum() {
      //设置相册上传数量，当接口返回result==1时，即当前商品设置了独立的相册数量设置；返回result==0时，即采用插件设置的公共限制数量
      let that = this;
      $http.get("plugin.photo-order.api.photo-goods.getPhotoGoods", { goods_id: that.$route.query.goodsId }, "").then(response => {
        if (response.result == 1) {
          let _max = response.data.goods_max_photo;
          let _min = response.data.goods_min_photo;
          if (_max != 0 && _max >= _min) {
            that.max_count = _max;
          } else {
            that.max_count =
              Number(_min) >= Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_max_pohot)
                ? _min
                : Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_max_pohot);
          }
          that.min_count = _min ? _min : Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_min_pohot);
        } else {
          that.max_count = Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_max_pohot); //最大上传张数
          that.min_count = Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_min_pohot)
            ? Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_min_pohot)
            : 1; //最小上传张数
        }
        if (!that.max_count) {
          that.isPhoto = false;
        }
      });
    },
    //获取当前位置信息，用于提交订单
    getCurrentOrderLocation() {
      return new Promise((resolve, reject) => {
        Toast.loading({
          message: "获取位置信息",
          forbidClick: true
        });
        let myLocation = JSON.parse(localStorage.getItem("myLocation"));
        if (myLocation && myLocation.addressComponent) {
          Toast.clear();
          resolve({
            positioning_success: 1,
            province: myLocation.addressComponent.province,
            city: myLocation.addressComponent.city
          });
        } else {
          let mapObj = new AMap.Map("iCenter");
          mapObj.plugin("AMap.Geolocation", () => {
            let geolocation = new AMap.Geolocation({
              enableHighAccuracy: true, // 是否使用高精度定位，默认:true
              timeout: 10000, // 超过10秒后停止定位，默认：无穷大
              maximumAge: 0, // 定位结果缓存0毫秒，默认：0
              convert: true, // 自动偏移坐标，偏移后的坐标为高德坐标，默认：true
              showButton: true, // 显示定位按钮，默认：true
              buttonPosition: "LB", // 定位按钮停靠位置，默认：'LB'，左下角
              buttonOffset: new AMap.Pixel(10, 20), // 定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
              showMarker: true, // 定位成功后在定位到的位置显示点标记，默认：true
              showCircle: true, // 定位成功后用圆圈表示定位精度范围，默认：true
              panToLocation: true, // 定位成功后将定位到的位置作为地图中心点，默认：true
              zoomToAccuracy: true // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
            });
            mapObj.addControl(geolocation);
            geolocation.getCurrentPosition();
            AMap.event.addListener(geolocation, "complete", obj => {
              Toast.clear();
              if (obj.addressComponent) {
                resolve({
                  positioning_success: 1,
                  province: obj.addressComponent.province,
                  city: obj.addressComponent.city
                });
              } else {
                resolve({
                  positioning_success: 0,
                  province: "",
                  city: ""
                });
              }
            }); // 返回定位信息
            AMap.event.addListener(geolocation, "error", () => {
              Toast.clear();
              resolve({
                positioning_success: 0,
                province: "",
                city: ""
              });
            }); // 返回定位出错信息
          });
        }
      });
    },

    // 整合了发票、是否显示个人信息接口
    getParams(cart_ids) {
      let json = {};
      if (this.root_tag == "store" && !cart_ids) {
        return;
      } else if (this.root_tag == "store" && cart_ids) {
        _cart_ids = cart_ids;
      }
      if (cart_ids && this.$route.query.cart_ids && this.$route.query.cart_ids.split) {
        _cart_ids = this.$route.query.cart_ids.split(",");
      }
      let good_ids = [];

      if (this.isCartsOrder) {
        // 购物车商品下单的循环商品
        for (let j = 0; j < this.goodsInfo.orders.length; j++) {
          for (let i = 0; i < this.goodsInfo.orders[j].order_goods.length; i++) {
            good_ids.push(this.goodsInfo.orders[j].order_goods[i].goods_id);
          }
        }
        if (this.fun.isTextEmpty(good_ids)) {
          // 为空跳回
          this.$router.go(-1);
          return;
        }
      } else {
        _goodsId = this.$route.query.goodsId;
        good_ids.push(_goodsId);
      }
      json = {
        goods_ids: JSON.stringify(good_ids)
      };
      $http
        .get("from.div-from.get-params", json, " ")
        .then(
          response => {
            if (response.result === 1) {
              let { deliveryTime } = response.data;
              this.deliveryTimeParams = deliveryTime || {};
              this.deliveryTimeParamsTime = this.deliveryTimeParams.time;
              if (this.$route.query.orderType != "groupBuy_open" || this.$route.query.orderType != "groupBuy_join") {
                this.isGetAgreementPay = true;
                // 获取是否显示支付协议
                this.AgreementPay = response.data.getPayProtocol;
              }
              //运费说明
              this.freightExplain = response.data.freightExplain;
              try {
                this.openCueCoupon = response.data.getCouponSet == 0 ? false : true; //是否开启下单优惠券提示
                this.checkTaxGoods(response.data.isDisplay);
                if (response.data.getMemberInfo) this.getMemberInfo(response.data.getMemberInfo);
                // if (response.data.explain) this.getExplain(response.data.explain);

                this.getInvoice(response.data.sinvoice);
                this.storeSearchBtn = response.data.storeSearch || {};
              } catch (error) {
                console.log(error);
              }
            } else {
              this.isGetAgreementPay = false;
            }
          },
          response => {
            this.isGetAgreementPay = false;
            console.log(response);
          }
        )
        .catch(err => {
          this.isGetAgreementPay = false;
          console.log(err);
        });
    },

    //是否海外商品
    checkTaxGoods(data) {
      if (data.status) {
        this.isTaxGoods = true;
        // 显示个人信息
        this.showMyinfo = data.status;
      } else {
        this.isTaxGoods = false;
        // 隐藏个人信息
        this.showMyinfo = false;
      }
    },

    // 配置用户信息
    getMemberInfo(data) {
      // 个人信息
      this.myRealname = data.realname;
      this.myIdcard = data.idcard;
    },

    // getExplain(data) {
    //   this.explain_title = data.explain_title;
    //   this.explain_content = data.explain_content;
    // },

    // 发票数据
    getInvoice(data) {
      this.$refs.invoicePop.initData(data);
      // this.invoiceData.papery_status = parseInt(data.invoice.papery);
      // this.invoiceData.electron_status = parseInt(data.invoice.electron);
      // if (!this.invoiceData.papery_status && !this.invoiceData.electron_status) {
      //   this.isShowInvoice = false;
      // }
    },
    subInvoice(data) {
      // 弹窗获取发票数据
      this.invoice_list = data;
    },

    // 直接购买
    getDataActionBuy(is_exchange) {
      let that = this;
      let json = {
        goods_id: _goodsId,
        total: _total,
        option_id: _optionsId,
        member_coupon_ids: this.assembleCoupons(),
        orders: JSON.stringify(this.assembleDeduction()),
        address: encodeURIComponent(JSON.stringify(this.currentAddress)), //encodeURIComponent为了解决地址#号问题
        dispatch_type_id: this.selected,
        mark: this.$route.query.mark ? this.$route.query.mark : 0,
        first_default: this.first_default || "" //是否首次请求，之后的请求都要回传这个参数。没有传这个参数的订单全部按默认首次请求处理
      };
      if (this.checkCouponList_new.length) {
        json.new_member_coupon_ids = this.assembleCoupons_new();
      }
      if (this.root_tag == "yzlease" && this.yz_lease_time.days) {
        json.lease_tenancy_terms_id = this.yz_lease_time.lease_term_id;
        json.nums_day = this.yz_lease_time.days;
        // json.total = this.yz_lease_time.days;
      }
      //自提点开启
      if (this.selected == "8") {
        json.package_deliver_id = this.defaultSelfCarry.id;
      }
      if (this.selected == "12") {
        // 门店自提点
        json.package_deliver_id = this.o2oSelfCarry.id;
      }

      if (this.root_tag == "fromExchange") {
        //兑换中心商品
        let _exchangeData = this.$route.query.exchangeData;
        if (this.fun.isTextEmpty(_exchangeData)) {
          // 为空跳回
          this.$router.go(-1);
          return;
        }
        json.data = _exchangeData;
        json.is_exchange = is_exchange == 0 ? 0 : 1;
      }
      if (this.$route.query.energy_machine_id) {
        json.energy_machine_id = this.$route.query.energy_machine_id;
      }
      if(this.$route.query.tag == 'new_auction'){
        json.new_auction_id = this.$route.params.new_auction_id;
        json.new_auction_pick_num = this.$route.params.new_auction_pick_num;
      }

      json = this.handleDataActionBuyUrl(json);
      if(this.checkCouponList_new.length){
        json.new_member_coupon_ids = this.assembleCoupons_new()
      }
      if (this.$route.query.orderType == "newRetail" && this.$route.query.retail_state == 2) {
        json.goods = JSON.parse(this.$route.query.goods) || []; // 自由发货
      }
      if (this.good_clicktag === 0) {
        this.good_clicktag = 1;
        $http.post(this.pre_order_url, json, "生成中", true).then(
          response => {
            // resule有return操作没有执行这段
            setTimeout(() => {
              that.good_clicktag = 0;
            }, 1000);
            if (response.result === 1) {
              let res = response.data;
              if (this.$route.query.tag == "reserve") {
                // 门店预约商品
                if (response.data.reserve_date) {
                  that.reserveDate = response.data.reserve_date.date;
                }
                if (response.data.reserve_deduction) {
                  that.reserve_deduction = response.data.reserve_deduction;
                }
                if (response.data.reserve_deduction_love) {
                  that.reserve_deduction_love = response.data.reserve_deduction_love;
                }
              }
              if(this.$route.query.tag == 'local_life'){
                this.local_life = res.local_life;
              }
              if (this.$route.query.tag == "tourAround") {
                this.orderShowIdCard = res.orders[0]?.travel_around_order.orderShowIdCard;
                this.bookingShowAddress = res.orders[0]?.travel_around_order.bookingShowAddress;
              }
              if (this.$route.query.tag == "cake") {
                this.cakeData(res); //处理蛋糕叔叔的配送方式和格外数据
              }
              if (that.$route.query.orderType == "groupBuy_open" || that.$route.query.orderType == "groupBuy_join") {
                //拼购支付协议
                that.isGetAgreementPay = true;
                that.AgreementPay = that.goodsInfo.together_purchase_agreement;
              }
              that.goodsInfo = response.data;
              that.cup_notice = true;
              that.setViewData(response.data); // 设置界面
              if (this.root_tag == "fromExchange") {
                that.defaultSelectCoupon(response.data.discount.member_coupons); // 设置默认优惠券信息
              } else {
                this.initCoupon(response.data.discount); // 设置优惠券信息
              }
            } else {
              that.cup_notice = true;
              if (response.msg.includes("errorCode:3000")) {
                this.$dialog
                  .confirm({
                    message: "查询范围失败，请重新选择地址或编辑经纬度！",
                    cancelButtonText: "返回上一页"
                  })
                  .then(() => {
                    this.yzAddressListOptions = {
                      is_open_store_delivery: this.is_open_store_delivery,
                      selected: this.selected
                    };
                    this.showAddress = true;
                  })
                  .catch(() => {
                    this.$router.go(-1);
                  });
                return;
              }
              this.$dialog
                .confirm({ message: response.msg })
                .then(() => {
                  if (response.data.address_error == "404") {
                    this.$router.push(this.fun.getUrl("address"));
                    return;
                  }

                  if (response.data.errorCode == "showAddress") {
                    return this.showAddressFun();//显示地址弹窗
                  }

                  if (!response.data.login_status) {
                    // 非跳转登录页才返回上一页
                    let _ReturnUrl = this.$store.state.orderErrReturnUrl;
                    if (_ReturnUrl) {
                      window.location.href = _ReturnUrl;
                      return;
                    }
                    if (this.root_tag != "yzlease") {
                      this.$router.go(-1);
                    }
                  }
                })
                .catch(() => {
                  this.$router.go(-1);
                });
            }
          },
          response => {
            console.log(response);
          }
        );
      }
    },

    // 购物车结算
    getDataActionCart() {
      let that = this;
      let json = {
        cart_ids: _cart_ids.toString() || [], // 预下单的购物车id是用，逗号拼接的字符串
        member_coupon_ids: this.assembleCoupons(),
        orders: JSON.stringify(this.assembleDeduction()),
        address: encodeURIComponent(JSON.stringify(this.currentAddress)),
        dispatch_type_id: this.selected
      };
      //自提点开启
      if (this.selected == "8") {
        json.package_deliver_id = this.defaultSelfCarry.id;
      }
      if (this.selected == "12") {
        // 门店自提点
        json.package_deliver_id = this.o2oSelfCarry.id;
      }

      this.order_other_json = {};
      json = this.handleDataActionCartUrl(json);
      $http.get(this.pre_order_url, json, "生成中", true).then(
        response => {
          if (response.result === 1) {
            that.goodsInfo = response.data;
            that.cup_notice = true;
            that.setViewData(response.data); // 设置界面
            that.initCoupon(response.data.discount); // 设置优惠券信息
          } else {
            Toast(response.msg);
            that.$router.go(-1);
            that.cup_notice = true;
          }
        },
        response => {
          console.log(response);
        }
      );
    },

    // 获取门店数据
    initStore(str) {
      const that = this;
      this.recipient_name = "";
      this.recipient_mobile = "";
      $http.get("plugin.store-cashier.frontend.store.get-store-info.get-info-by-store-id", { store_id: this.store_id || this.$route.query.groupStoreID || this.$route.query.store_id }, " ").then(
        response => {
          if (response.result === 1) {
            that.store_info = response.data;
            that.store_carry = response.data.store_carry;
            if (str !== "is_activity" && !that.$route.query.groupStoreID) {
              // 门店拓客  门店预约 门店拼团不请求
              that.getDataActionStoreCart();
            }
            //开启门店配送  门店配送数据
            if (that.store_info.dispatch_type.indexOf("3") > -1 || that.store_info.dispatch_type.indexOf(3) > -1) {
              if (that.store_info.store_delivery && that.store_info.store_delivery.delivery_status == 1) {
                that.is_show_store_delivery = true;
              }

              if ((that.store_info.store_delivery && that.store_info.store_delivery.delivery_status == 1) || that.store_info.need_lat == 1) {
                that.is_open_store_delivery = true;
                that.delivery_amount = that.store_info.store_delivery ? that.store_info.store_delivery.delivery_amount : 0;
                that.delivery_note = that.store_info.store_delivery ? that.store_info.store_delivery.delivery_note : "";
                that.delivery_note = that.delivery_note.replace(/\n|\r/g, "<br/>"); //文本域换行处理
                let delivery_area = that.store_info.store_delivery && that.store_info.store_delivery.delivery_area ? that.store_info.store_delivery.delivery_area || [] : [];
                let locations = that.store_info.store_delivery ? that.store_info.store_delivery.locations : {};
                let arr_delivery_area = [];
                delivery_area.forEach((item, index) => {
                  arr_delivery_area.push([Number(item.R), Number(item.Q)]);
                });
                that.delivery_area = arr_delivery_area;
                that.locations = [Number(locations.longitude).toFixed(6), Number(locations.latitude).toFixed(6)];
                this.address_name = that.store_info.store_delivery ? that.store_info.store_delivery.address_name : "";
                this.is_custom = that.store_info.store_delivery ? that.store_info.store_delivery.is_custom : 0;
              }
            }
          } else {
            Toast(response.msg);
            that.$router.go(-1);
          }
        },
        response => {
          console.log(response);
        }
      );
    },
    //门店过期商品下单
    getCashGood() {
      $http.get("plugin.store-cashier.frontend.store.enter.getSetGoodsId", {}, "").then(
        response => {
          if (response.result === 1) {
            this.goods_id = response.data.goods_id;
            if (!response.data.store) {
              _goodsId = this.goods_id;
              this.root_tag = "-2";
              this.store_id = 0;
              this.getDataActionBuy();
            } else {
              this.root_tag = "store";

              this.store_info = response.data.store;
              this.store_id = this.store_info.id || this.store_info.store_id;
              this.getDataActionStoreCart();
            }
          } else {
            Toast(response.msg);
          }
        },
        response => {
          console.log(response);
        }
      );
    },
    // 门店购物车商品
    getDataActionStoreCart() {
      if (!this.store_id) {
        return;
      }
      if (this.storeCarts.length > 0) {
        // 已经有storeCarts就不重复请求了
        this.cup_notice = true;
        this.getStoreCartBuy(this.storeCarts);
        return;
      }
      if (_cart_ids && _cart_ids.length > 0) {
        this.storeCarts = _cart_ids;
        this.getDispatchMethod(this.storeCarts.toString());
        return;
      }
      let that = this;
      $http
        .get(
          "plugin.store-cashier.frontend.shoppingCart.member-cart.index",
          {
            store_id: this.store_id,
            just_live_install: this.$route.query.just_live_install || 0
          },
          ""
        )
        .then(
          response => {
            if (response.result === 1) {
              that.cup_notice = true;
              that.storeCarts = [];
              response.data.forEach(item => {
                if (item.is_failure == 0) {
                  // 过滤过期门店商品
                  that.storeCarts.push(item.id);
                }
              });
              // 在setViewData的时候调用了 暂时注释
              // if (!that.isGetAgreementPay) {
              //   that.getParams(that.storeCarts);
              // }

              //第请求接口获取配送方式后，取默认第一个的dispatch_type_id再请求预下单接口;  挂单POrder走固定的配送方式
              this.getDispatchMethod(that.storeCarts.toString());
              if (JSON.parse(window.localStorage.getItem("globalParameter")).is_open_photo_order == "1" && that.storeCarts.length == 1) {
                //门店商品仅单个商品下单才可进行上传相册,多个商品购物车结算不开启
                console.log("开启相册上传模块");
                that.isPhoto = true; //开启相册上传模块
                that.$nextTick(() => {
                  that.$refs.yzUploader.initData();
                });
                that.max_count = Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_max_pohot); //最大上传张数
                that.min_count = Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_min_pohot)
                  ? Number(JSON.parse(window.localStorage.getItem("globalParameter")).photo_order_min_pohot)
                  : 1; //最小上传张数
              } else if (JSON.parse(window.localStorage.getItem("globalParameter")).is_open_photo_order == "1") {
                that.storeNo_photo = true;
              }
            } else {
              that.cup_notice = true;
              alert("无商品");
            }
          },
          response => {}
        );
    },
    // 门店结算
    getStoreCartBuy(cart_ids) {
      let that = this;
      let json = {
        cart_ids: cart_ids,
        store_id: this.store_id,
        dispatch_type_id: this.selected,
        member_coupon_ids: this.assembleCoupons(),
        orders: JSON.stringify(this.assembleDeduction()),
        address: encodeURIComponent(JSON.stringify(this.currentAddress))
      };
      let _url = "plugin.store-cashier.frontend.store.cart-buy";
      if (this.$route.query.just_live_install) {
        _url = "plugin.live-install.frontend.store-cart-buy.index";
        json.dispatch_type_id = 1;
        json.live_install_order_replace_uid = this.$route.query.live_install_order_replace_uid;
      }
      $http.get(_url, json, "生成中").then(
        response => {
          if (response.result === 1) {
            that.goodsInfo = response.data;
            that.setViewData(response.data, cart_ids); // 设置界面
            that.initCoupon(response.data.discount); // 设置优惠券信息
          } else {
            // 编辑地址时不提示错误信息
            if (that.showAddress) {
              return;
            }
            if (response.msg === "请完善地址经纬度信息") {
              // 门店配送提示不能返回上一页 #62588
              this.show_address = false;
              that.$dialog.alert({ message: "请完善收件人的地址经纬度信息" });
            } else {
              that.$dialog.alert({ message: response.msg }).then(() => {
                if (response.msg.indexOf("配送范围") < 0) {
                  that.$router.go(-1);
                }
              });
            }
          }
        },
        response => {
          console.log(response);
        }
      );
    },

    // 租赁购物车结算
    getRentDataActionCart(right, rent) {
      let that = this;
      let json = {
        lease_rights: right,
        lease_term: rent,
        member_coupon_ids: this.assembleCoupons(),
        orders: JSON.stringify(this.assembleDeduction()),
        address: encodeURIComponent(JSON.stringify(this.currentAddress)),
        dispatch_type_id: this.selected,
        mark: this.$route.query.mark ? this.$route.query.mark : 0
      };

      //自提点开启
      if (this.selected == "8") {
        json.package_deliver_id = this.defaultSelfCarry.id;
      }
      if (this.selected == "12") {
        // 门店自提点
        json.package_deliver_id = this.o2oSelfCarry.id;
      }

      if (this.root_tag == "rentCartBuy") {
        json.cart_ids = _cart_ids.toString();

        $http.get("plugin.lease-toy.api.order.cart-buy", json, "生成中").then(
          response => {
            if (response.result == 1) {
              that.goodsInfo = response.data;
              that.cup_notice = true;
              that.setViewData(response.data); // 设置界面
              that.initCoupon(response.data.discount); // 设置优惠券信息
            } else {
              that.cup_notice = true;
              Toast(response.msg);
              that.$router.go(-1);
            }
          },
          response => {
            console.log(response);
          }
        );
      } else if (this.root_tag == "rentBuy") {
        json.goods_id = _goodsId;
        json.total = _total;
        json.option_id = _optionsId;

        $http.get("plugin.lease-toy.api.order.goods-buy", json, "生成中").then(
          response => {
            if (response.result == 1) {
              that.goodsInfo = response.data;
              that.cup_notice = true;
              that.setViewData(response.data); // 设置界面
              that.initCoupon(response.data.discount); // 设置优惠券信息
            } else {
              that.cup_notice = true;
              Toast(response.msg);
              that.$router.go(-1);
            }
          },
          response => {
            console.log(response);
          }
        );
      }
    },
    // 获取租期列表
    getRentTimeList() {
      $http
        .get("plugin.lease-toy.api.lease-term.index", {})
        .then(response => {
          if (response.result == 1) {
            this.rentTime = response.data.list;
            this.rentFree = response.data.level.rent_free;
            this.agreeCon = response.data.lease_toy_set;
            this.rent_deposit_free = response.data.level.deposit_free;
            this.rent_free = response.data.level.rent_free;
          }
        })
        .catch(error => {
          console.log(error);
        });
    },
    //租赁商品预下单
    rentGoodBuy() {
      if (this.isOpenRight) {
        this.getRentDataActionCart(window.localStorage.getItem("rentTimeRight"), []);
      } else {
        if (this.currentIndex == "999") {
          if (!this.fun.isTextEmpty(window.localStorage.getItem("rentTimeSelf"))) {
            let val = window.localStorage.getItem("rentTimeSelf");
            this.getRentDataActionCart([], val);
          } else {
            this.getRentDataActionCart([], []);
          }
        } else {
          if (!this.fun.isTextEmpty(window.localStorage.getItem("rentTimeChoose"))) {
            let param = window.localStorage.getItem("rentTimeChoose");
            this.getRentDataActionCart([], param);
          }
        }
      }
    },

    //获取批发区下单页类型判断--挂单
    getPendingOrder_type() {
      if (this.selected == 1) {
        this.getDataActionBuy();
        return;
      }
      //挂单不适合配送方式
      $http
        .get("plugin.pending-order.frontend.wholesale-area.pending-order-type", {}, "")
        .then(response => {
          if (response.result == 1) {
            if (response.data.status == 0) {
              this.dispatch = [
                { name: "零售", dispatch_type_id: 0 },
                { name: "自用", dispatch_type_id: 1 }
              ];
              this.selected = 0;
            } else {
              this.dispatch = [{ name: "自用", dispatch_type_id: 1 }];
              this.selected = 1;
            }
            this.getDataActionBuy(); // 直接购买
          } else {
            Toast(response.msg);
          }
        })
        .catch(error => {
          console.log(error);
        });
    },

    // 应用市场判断域名
    getOrderDomain(_data) {
      for (let j = 0; j < _data.length; j++) {
        if (_data[j].plugin_id === 58) {
          this.plugin_id = 58;
        }
        if (_data[j].domain !== undefined) {
          // 是否应用市场产品的商品
          this.show_domain = true;
        }
      }
      //判断有订单是否有绑定域名  有则取第一个
      //return 已绑定域名
      for (let j = 0; j < _data.length; j++) {
        if (_data[j].domain) {
          console.log("已绑定域名");
          return _data[j].domain;
        }
      }
      return "";
    },
    // 判断是否需要地址
    isOrderAddress_M(_data) {
      //判断是否有订单需要填写地址，有一单需要填写地址则需要填写地址才可以下单
      if (this.$route.query.device_id) return true;
      if (this.$route.query.tag == 'timeAppoint') return true;
      //return false 提交订单需要填写地址
      for (let j = 0; j < _data.length; j++) {
        if (this.phone_bill_pro_goods) {
          if (!_data[j].not_show_address) {
            return false;
          }
        } else if (this.oil_account && this.oil_mobile) {
          if (!_data[j].not_show_address) {
            return false;
          }
        } else if (this.$route.query.coffee_pre_order_sn) {
          // 如果是咖啡机收银台预下单就不要验证地址
          if (!_data[j].not_show_address) {
            return false;
          }
        } else if (this.bookingShowAddress) {
          //如果是周边游，bookingShowAddress等于1是周边游第三方需要填写地址
          return false;
        } else {
          if (!_data[j].need_address) {
            return false;
          }
        }
      }
      return true;
    },
    // 设置界面
    setViewData(data, cart_ids) {
      if(data.beforePageDialog) {
        this.$dialog.confirm({
          message: data.beforePageDialog.message,
          confirmButtonText: data.beforePageDialog.confirmButtonText,
          cancelButtonText: data.beforePageDialog.close
        })
          .then(() => {
            // on confirm
          })
          .catch(() => {
            return this.$router.go(-1);
          });
      }
      if( this.root_tag == 'distribution_coupon' && data.distribution_coupon.length > 0 ){
        this.distribution_couponData = data.distribution_coupon;
      }
      if (data.discount && data.discount.default_deduction && data.discount.default_deduction != 0) {
        // 获取第一次接口默认积分抵扣
        this.default_deduction = data.discount.default_deduction;
      }
      // 中台租赁租期获取
      if (data.yz_lease_goods) {
        this.rentTime = data.yz_lease_goods.rent_term;
        this.isRightChoose = true;
        this.agreeCon = data.yz_lease_goods.policy;
      }
      // if (this.$route.query.myinfo) {
      //   // 如果是修改信息页面回来就重新请求
      //   this.getParams_status = false;
      // }
      if (!this.getParams_status) {
        this.getParams_status = true;
        this.getParams(cart_ids);
      }
      this.recommend_goods = data.dispatch.recommend_goods ? data.dispatch.recommend_goods : [];
      this.setAddressViewData(data.dispatch.default_member_address); // 设置地址界面
      if (!this.consigneeName) this.consigneeName = data.dispatch.custom_data?.custom_consignee;
      if (!this.consigneeMobile) this.consigneeMobile = data.dispatch.custom_data?.custom_phone;
      //判断是否有订单需要填写地址
      console.log("data.orders");
      this.show_address = this.isOrderAddress_M(data.orders);
      if (data.is_agency_restock && data.is_agency_restock == 1) {
        this.show_address = true;
      }
      if (this.show_address) {
        this.selected = 0;
      }

      this.order_data = data.orders;
      //if (this.default_deduction != 0) { //#70842
      // 默认积分抵扣要获取order_deductions里checked=true的传给第二次接口
      for (let i = 0; i < this.order_data.length; i++) {
        let arr = this.order_data[i].order_deductions;
        let service_fees = this.order_data[i].order_service_fees;
        if (this.order_data[i].order_deductions && !(this.order_data[i].order_deductions instanceof Array)) {
          arr = Object.values(this.order_data[i].order_deductions);
        }
        if (this.order_data[i].order_service_fees && !(this.order_data[i].order_service_fees instanceof Array)) {
          service_fees = Object.values(this.order_data[i].order_service_fees);
        }
        if (arr) {
          arr.map(item => {
            if (item.checked) {
              this.screenDiscount(this.order_data[i], item);
            }
          });
        }
        if (service_fees) {
          service_fees.map(item => {
            if (item.checked && !this.service_fee[this.order_data[i].pre_id]) {
              this.service_fee[this.order_data[i].pre_id] = [];
              this.service_fee[this.order_data[i].pre_id].push(item.code);
              this.serviceFeesHandle(this.order_data[i], item);
            }
          });
        }
      }
      // }

      this.good_clicktag = 0;
      this.service_fee_items = data.service_fee_items;
      this.tax_fee_items = data.tax_fee_items;
      // 处理提交表单后，点击积分抵扣和优惠券这些需要重新请求接口数据时，之前保存的表单id被覆盖问题
      if (!this.fun.isTextEmpty(this.oldOrder_data)) {
        for (let index = 0; index < this.goodsInfo.orders.length; index++) {
          this.goodsInfo.orders[index].order_goods = this.oldOrder_data.orders[index].order_goods;
        }
      }

      this.dispatch.forEach(items => {
        if (items.dispatch_type_id == 8) {
          console.log("有自提点配送方式，请求定位获取自提点列表");
          if (!this.$route.params.changeSelfCarry || this.fun.isTextEmpty(this.defaultSelfCarry.id)) {
            this.getLocation("shop");
          }
        }
        if (items.dispatch_type_id == 12) {
          console.log("有门店自提点配送方式，请求定位获取自提点列表", this.o2oSelfCarry);
          if (!this.o2oSelfCarry.id) {
            this.getLocation("o2o");
          }
        }
      });

      //判断有订单是否有绑定域名
      this.shop_domain = this.getOrderDomain(data.orders);
      this.findGoodOpen(); // 循环订单列表是否开启表单和慢充
      this.price = data.total_price; // 设置总价格（合计）
      this.total_items = data.amount_items;
      if(data.broadnet_card){
        this.broadnet_card = data.broadnet_card; //是否显示广电表单
      }
      if (this.root_tag == "reserve") {
        this.delivery_information = data.delivery_information;
      }
      this.discount_amount_items = data.discount_amount_items;

      if (this.root_tag == "store" && this.price < 0) {
        this.$router.push(this.fun.getUrl("o2oHome"));
        this.$dialog.alert({ message: "下单错误" });
      }
      if (data.address_code) {
        this.show_add_address = data.address_code.show_add_address ? data.address_code.show_add_address : false;
      }
      if (data.is_diy_form_jump == 1) this.is_diy_form_jump = data.is_diy_form_jump;
      this.getDistributionInfo(data.last_deliver_user_info);
      this.first_default = data.first_default; //是否首次请求，之后的请求都要回传这个参数。没有传这个参数的订单全部按默认首次请求处理
    },
    // 设置地址界面
    setAddressViewData(data) {
      let model = data;
      if (model == undefined || model == "" || model == []) {
        return;
      }
      if (this.$route.query.tag === "cake") {
        this.cakeCity = model.city;
        this.getRule();
        this.shopDetail = "";
        this.shopName = "";
        this.shopId = "";
      }

      // 设置地址id
      currentAddId = model.id || model.address_id;
      this.currentAddress = model;
      this.realname = this.fun.isTextEmpty(model.username) ? "" : model.username;
      this.mobile = this.fun.isTextEmpty(model.mobile) ? "" : model.mobile;
      this.address = this.fun.isTextEmpty(model.province)
        ? model.address
          ? model.address
          : ""
        : model.province + " " + model.city + " " + model.district + " " + (this.fun.isTextEmpty(model.street) ? "" : model.street + " ") + model.address;
      this.addressData = model;
      if (this.selected == "11") {
        if (model && (!model.latitude || !model.longitude)) {
          // #12172 优化
          this.$dialog.alert({ message: `将获取您的位置，请确定后重新提交订单` }).then(() => {
            this.autoAddress(model);
          });
          return;
        }
      }
    },
    autoAddress(model) {
      let that = this;
      let addressId = model.id;
      this.fun
        .getLocation("正在定位")
        .then(res => {
          let point = this.fun.bd_encrypt(res.point.lng, res.point.lat);
          $http.get("member.member-address.update-location", { address_id: addressId, latitude: point.lat, longitude: point.lng }, "获取中...").then(
            function(response) {
              if (response.result == 1) {
                model.latitude = point.lat;
                model.longitude = point.lng;
                that.currentAddress = model;
              } else {
                that.$dialog.alert({ message: `请重新编辑您的地址，在地图上选择您所在的位置` });
              }
            },
            function(response) {
              console.log(response);
            }
          );
        })
        .catch(err => {});
    },
    // 选择地址后重新计算数据
    requestByAddress(title, name) {
      // 初始化同城配送禁用状态
      this.yz_subscribe_disabled = false;
      // 重新计算
      if (this.selected == "10") {
        // 定位
        this.fun
          .getLocation("正在定位")
          .then(res => {
            let ares = this.fun.bd_encrypt(res.point.lng, res.point.lat);
            this.supp_point.lng = ares.lng;
            this.supp_point.lat = ares.lat;
            this.supp_point.address = res.address;
          })
          .catch(err => {});
      }
      if (this.selected == "11") {
        this.getDeliverySetting();
      } else {
        this.handleBuy("1");
      }
    },

    //选择同城配送时请求
    getDeliverySetting() {
      // if(this.selected=="11"){
      //   if(!currentAddress.latitude || !currentAddress.longitude){
      //     this.$dialog.alert({ message: "请重新编辑您的地址，在地图上选择您所在的位置" });
      //   }
      // }
      this.is_open_store_delivery = true;
      if (this.cityDelivery != null) {
        this.order_data.forEach(item => {
          if (this.cityDelivery.min_amount * 1 > item.goods_price * 1) {
            // *1 只是为了转数字类型
            this.yz_subscribe_disabled = true; //商品价格不够最低配送，按钮灰色不能提交
          }
        });
        this.handleBuy("1");
        return;
      }
      $http.get("plugin.city-delivery.frontend.order.getDeliverySetting", {}).then(res => {
        if (res.result === 1) {
          this.cityDelivery = res.data;
          this.locations = [Number(res.data.fence_setting.store_longitude).toFixed(6), Number(res.data.fence_setting.store_latitude).toFixed(6)];
          this.delivery_area = res.data.fence_setting.delivery_area;
          this.$refs.deliveryTime.setListData(res.data.time_setting, res.data.default_choose);
          this.order_data.forEach(item => {
            if (res.data.min_amount * 1 > item.goods_price * 1) {
              // *1 只是为了转数字类型
              this.yz_subscribe_disabled = true; //商品价格不够最低配送，按钮灰色不能提交
            }
          });
          if (!res.data.default_choose) {
            this.handleBuy("1");
          }
        }
      });
    },

    //显示地址pop
    showAddressFun(key) {
      // 获取收货地址
      this.yzAddressListOptions = {
        is_open_store_delivery: this.is_open_store_delivery,
        selected: this.selected
      };
      this.addressList_caller = "express";
      this.showAddress = true;
      this.$refs.yz_showAddressShop.add_address = this.show_add_address;
      if (key == "code") {
        this.codeShow = false;
      }
    },
    //发票插件显示地址
    invoiceShowAddressFun() {
      this.yzAddressListOptions = {
        is_open_store_delivery: this.is_open_store_delivery,
        selected: this.selected
      };
      this.addressList_caller = "invoice";
      this.showAddress = true;
    },
    code_confirmSelectAddress(item) {
      this.setAddressViewData(item);
      this.requestByAddress(); // 选择地址后重新计算
      this.codeShow = false;
      this.addressData = item;
      this.submitBtnPost();
    },
    // 增加/修改地址
    confirmSelectAddress(item) {
      if (this.addressList_caller == "express") {
        this.setAddressViewData(item);
        this.requestByAddress(); // 选择地址后重新计算
        this.showAddress = false;
      } else if (this.addressList_caller == "invoice") {
        this.$refs.invoicePop.setAddress(item);
        this.showAddress = false;
      }
      this.addressData = item;
    },

    // 检查配送方式数据
    checkDispatch() {
      //渠道商订货补货不需要填写地址
      let isNeedAddress = !(
        this.$route.query.tag == "channel" ||
        this.$route.query.tag == "channel_Replenishment" ||
        this.$route.query.tag == "channel_TCOrder" ||
        this.$route.query.tag == "timeAppoint" ||
        this.$route.query.tag == "vending_machine"
      );
      if (this.$route.query.tag == "vending_machine") return true;
      if (this.selected == "8" || this.selected == "12" || this.selected == "15") {
        if (this.fun.isTextEmpty(this.distributionUserName)) {
          Toast("请填写提货人姓名");
          this.submit_active = true;
          return false;
        }
        if (this.fun.isTextEmpty(this.distributionUserMobile)) {
          Toast("请输入提货人手机");
          this.submit_active = true;
          return false;
        }
      }

      if (this.selected == "8" || this.selected == "12") {
        if ((this.selected == "8" && !this.defaultSelfCarry.id) || (this.selected == "12" && !this.o2oSelfCarry.id)) {
          Toast("请选择自提点");
          this.submit_active = true;
          return false;
        }
        this.save_ztd_LocalStorage(this.distributionUserName, this.distributionUserMobile);
      }

      if (this.selected == "2" && this.store_info.delivery_information == 1) {
        if (this.fun.isTextEmpty(this.linkinfo.name) || this.fun.isTextEmpty(this.linkinfo.mobile)) {
          Toast("请输入提货人信息");
          this.submit_active = true;
          return false;
        } else {
          this.save_ztd_LocalStorage(this.linkinfo.name, this.linkinfo.mobile);
        }
      }

      if (this.selected == "2" && this.store_info.delivery_information != 0 && this.fun.isMoblie(this.linkinfo.mobile)) {
        this.$dialog.alert({ message: "请输入正确的手机号" });
        this.submit_active = true;
        return false;
      }
      if (!this.show_address && (this.selected == "0" || this.selected == "1" || this.selected == "3") && isNeedAddress && !this.ele_no_showAdress) {
        if (this.fun.isTextEmpty(currentAddId)) {
          Toast("请选择收货地址");
          this.submit_active = true;
          return false;
        }
      }

      return true;
    },
    // 检查提交数据
    checkSubmit() {
      if (this.showMyinfo) {
        if (this.fun.isTextEmpty(this.myRealname)||this.fun.isTextEmpty(this.myIdcard)) {
          Toast("请完善个人信息");
          this.showFrom = true;
          return false;
        }
      }

      if (this.deliveryTimeParams.status == 1) {
        this.$refs.deliveryTimeFormValidate.validate();
        if (!this.shop_delivery_day || !this.shop_delivery_time) {
          Toast("请填写配送日期/时间");
          return false;
        }
      }
      if (this.$route.query.tag == "timeAppoint") {
        if (this.fun.isTextEmpty(this.reserve_order.customer_name)) {
          Toast("请填写联系人");
          return false;
        }
        if (this.fun.isTextEmpty(this.reserve_order.customer_tel)) {
          Toast("请填写联系电话");
          return false;
        }
      }
      if (this.isPhoto) {
        //相册模块开启下单时判断 是否符合条件
        if (this.fileList1.length < this.min_count) {
          this.$dialog.alert({ message: `上传图片张数不应少于${this.min_count}张` });
          return false;
        }
      }
      if (this.mustSelectCoupon()) {
        // 提示优惠券【51723】
        return false;
      }
      if (this.cpsType == "1" && this.cpsTxt == "") {
        Toast("请输入帐号");
        return false;
      }

      if (this.camilo_resources_coupon_type == 1) {
        // 卡券商品
        if (!this.recharge_number) {
          Toast("请输入充值账号");
          return false;
        }
      }

      if (this.selected == 16) {
        // 卡券商品
        if (!this.extra_info.ecp_number) {
          return this.$toast("请填写收件人门市代号");
        }
        if (!this.extra_info.sleectEcp) {
          return this.$toast("请选择收件人物流类型");
        }
      }

      if (this.$route.query.orderType == "newRetail" && this.$route.query.retail_state == 3 && this.price == 0) {
        //新零售-自由发货下单不能为0
        Toast("价格有误");
        return false;
      }

      if (!this.isAllDFOk()) {
        if (this.is_diy_form_jump == 0) {
          Toast("请填写表单！");
          this.submit_active = true;
          return false;
        }
        if (this.is_diy_form_jump == 1) {
          for (let i = 0; i < this.order_data.length; i++) {
            for (let g = 0; g < this.order_data[i].order_goods.length; g++) {
              if (this.order_data[i].order_goods[g].diy_form && !this.order_data[i].order_goods[g].diy_form.diyform_data_id) {
                this.getGoodDFData(this.order_data[i].order_goods[g].pre_id, this.order_data[i].order_goods[g].diy_form.form_id, null);
                return false;
              }
            }
          }
        }
      }

      // 手机慢充
      if (this.show_recharge_mobile && !this.recharge_mobile) {
        Toast("请输入充值手机号码！");
        this.submit_active = true;
        return false;
      } else if (this.show_recharge_mobile && this.recharge_mobile) {
        let reg_txt = /^[1][0-9]{10}$/;
        if (!reg_txt.test(this.recharge_mobile)) {
          Toast("请输入正确的充值手机号码！");
          this.submit_active = true;
          return false;
        }
      }

      if (this.show_domain && !this.shop_domain) {
        Toast("请先新增/绑定站点");
        this.submit_active = true;
        return false;
      }

      if (!this.checkDispatch()) {
        return false;
      }

      if (this.AgreementPay && !this.isRent) {
        if (!this.agreementPay) {
          Toast("请勾选支付协议");
          this.submit_active = true;
          return false;
        }
      }

      if (this.isRent && !this.agreement) {
        Toast("请勾选租赁协议");
        this.submit_active = true;
        return false;
      }

      return true;
    },
    // 上门安装
    isHasInstall() {
      //判断是否有勾选了上门安装服务
      for (let j = 0; j < this.service_fee_items.length; j++) {
        if (this.service_fee_items[j].code == "liveInstall") {
          return true;
        }
      }
      return false;
    },
    // 检查上门安装数据
    checkInstall() {
      //有勾选了上门安装服务，需要填写经纬度和时间
      if (!this.installDate) {
        Toast("请选择预约时间！");
        return false;
      }
      if (!this.location || !this.location.point || !this.location.point.lat) {
        Toast("请选择地理位置！");
        return false;
      }
      if (this.fun.isMoblie(this.linkinfo.mobile)) {
        this.$dialog.alert({ message: "请输入正确的手机号" });
        return false;
      }

      return true;
    },
    diyFromEdit(e) {
      this.activeDYGoodID = e.per_id;
      let form_id = e.form_id;
      let data_id = e.form_data_id;
      this.codeShow = false;
      this.getGoodDFData(this.activeDYGoodID, form_id, data_id);
    },
    getDiyForm() {
      this.codeShow = true;
      this.$nextTick(() => {
        this.$refs.yz_showAddress.code_editAddress(this.currentAddress);
        this.$refs.yz_showAddress.getIsOpenAddress();
      });
    },
    onClickRight() {
      // this.submit()
      this.codeShow = false;
      this.$refs.yz_addressList.showAddAddress();
    },
    // 统一商品提交订单
    submit(key) {
      let code = this.address_codeEnable ? true : false;
      if (this.yz_subscribe_disabled) return;

      if (!this.goodsInfo.orders) {
        return;
      }
      if (!this.checkSubmit()) {
        return;
      }
      if (this.$route.query.tag === "tourAround" && this.bookingShowAddress == "0") {
        //bookingShowAddress等于0，周边游开启不需要配送地址，不需要填写表单地址
        this.submitBtnPost();
        return;
      }
      if (code && this.selected == 1) {
        this.getDiyForm();
        return;
      }
      this.submitBtnPost();
    },
    submitBtnPost() {
      let json = this.assembleJson();
      if (this.$route.query.tag === "tourAround") {
        if (this.orderShowIdCard && this.fun.isTextEmpty(this.idCard)) {
          Toast("身份证必填");
          return;
        }
        if (this.fun.isTextEmpty(this.customerName)) {
          Toast("请填写姓名");
          return;
        }
        if (this.fun.isTextEmpty(this.customerPhoneNumber)) {
          Toast("请填写手机号码");
          return;
        }
        if (this.orderShowDate == 1 && this.fun.isTextEmpty(this.travelAroundTime)) {
          Toast("请填写使用时间");
          return;
        }
        if (this.bookingShowAddress == "0" && this.address == "") {
          //this.bookingShowAddress等于0，周边游第三方不需要配送地址，商城没有默认地址，提示客户设置默认地址
          this.$toast("请设置默认地址");
          this.addressList_caller = "express";
          this.showAddress = true;
          return;
        }
        json.customerName = this.customerName;
        json.customerPhoneNumber = this.customerPhoneNumber;
        json.memo = this.memo;
        json.idCard = this.idCard;
        json.travelDate = this.travelAroundTime;
      }
      //蛋糕叔叔的下单信息
      if (this.$route.query.tag === "cake") {
        if (this.fun.isTextEmpty(this.cakeMoblie)) {
          Toast("请输入订货人手机号");
          return;
        }
        if (this.cakeShipType === "delivery" || this.cakeShipType === "shop") {
          if (this.fun.isTextEmpty(this.cakeShipDate)) {
            Toast("请选择配送日期");
            return;
          }
          if (this.fun.isTextEmpty(this.shipTimeText)) {
            Toast("请选择配送时间");
            return;
          }
        }
        json.dispatch_type_id = 0; //不使用旧商城的配送方式
        json.city_cake = this.cakeCity;
        json.cake_ship_type = this.cakeShipType;
        json.ship_date = this.cakeShipDate;
        json.ship_time_text = this.shipTimeText;
        json.buyer_phone = this.cakeMoblie;
        if (this.canTake === "1" || this.canTake === 1) {
          json.cake_shop_id = this.shopId;
          json.cake_shop_detail = this.shopDetail;
          json.cake_shop_name = this.shopName;
        }
      }
      if (this.$route.query.energy_machine_id) {
        json.energy_machine_id = this.$route.query.energy_machine_id;
      }
      if (this.store_id && this.$route.query.tag != "reserve") {
        // 门店下单
        this.order_url = "plugin.store-cashier.frontend.store.create";
        if (this.$route.query.energy_machine_id) {
          this.order_url = "plugin.energy-machine.frontend.store-create.index";
        }
        if (this.isHasInstall()) {
          //有勾选了上门安装服务，需要填写经纬度和时间
          if (!this.checkInstall) {
            return;
          }
          let live_install_json = {
            live_install: {
              longitude: this.location.point.lng,
              latitude: this.location.point.lat,
              reserve_time: this.fun.getTimestamp(this.installDate),
              install_comment: this.install_comment
            }
          };
          if (this.$route.query.just_live_install) {
            this.order_url = "plugin.live-install.frontend.store-create.index";
            live_install_json.live_install_order_replace_uid = this.$route.query.live_install_order_replace_uid;
            live_install_json.dispatch_type_id = 1;
          }
          Object.assign(json, live_install_json);
        }
      }
      if (this.selected == "10") {
        if (json.supplier_driver_distribution_address) {
          if (this.fun.isTextEmpty(json.supplier_driver_distribution_address.lat) || this.fun.isTextEmpty(json.supplier_driver_distribution_address.lng)) {
            Toast("请选择供应商配送定位");
            return;
          }
        }
      }
      if (this.selected == "11") {
        // selected == "11" 同城配送
        if (this.cityDelivery.distance_type == 3) {
          if (!this.cityDelivery_community.id) {
            Toast("请选择配送社区");
            return;
          }
          json.community_id = this.cityDelivery_community.id;
        }
        if (this.cityDelivery.future_state == 1) {
          if (!this.cityDelivery_deliveryTime.start_time || !this.cityDelivery_deliveryTime.end_time) {
            Toast("请选择配送时间");
            return;
          }
          json.expect_start_time = this.cityDelivery_deliveryTime.start_time;
          json.expect_end_time = this.cityDelivery_deliveryTime.end_time;
        }
      }
      // 卡券开启不需要地址 #22040
      if (this.camilo_resources_coupon_type && this.plugin_setting.yz_supply_camilo_resources.is_default_order_address == "0") {
        json.address = "";
      }
      if(this.broadnet_card){
        let broadnet_card_info = this.$refs.broadnetCardChild.postData();
        if(!broadnet_card_info.val){
          this.$toast(broadnet_card_info.msg);
          return
        }else{
          json.broadnet_card_info = broadnet_card_info.data;
        }
      }
      if (this.submit_active == true) {
        this.submit_active = false;

        if (this.clicktag === 0) {
          this.clicktag = 1;

          $http
            .post(this.order_url, json, "提交中")
            .then(
              response => {
                if (response.result === 1) {
                  this.deleteAddressData();
                  if (this.isRent) {
                    this.clearStorage();
                  }
                  let data = response.data;
                  let orderJson = {
                    status: "2",
                    order_ids: response.data.order_ids
                  };
                  let api = "";
                  if (this.store_id && this.$route.query.tag == "store") {
                    orderJson.store_id = this.store_id;
                  }
                  if (this.is_cps) {
                    // 聚合cps商品下单
                    orderJson.iscps = true;
                  }
                  if (this.fun.isCPS()) {
                    if (this.fun.isIosOrAndroid() === "ios") {
                      toGoodBuyIOS({ body: "toGoodBuyIOS" });
                    }
                  }
                  localStorage.setItem("selfCarryInfo", {}); //清理提货信息，下次进入优先接口返回
                  localStorage.removeItem("feast_system_param"); //清理提货信息，下次进入优先接口返回
                  if (this.$route.query.tag === "tourAround") {
                    //周边游调用的新支付
                    api = "plugin.travel-around.frontend.payment.payment";
                    orderJson.order_ids = response.data.order_id;
                    let aroundOrder = {
                      api: api,
                      tag: "tourAround",
                      ordersn: response.data.order_sn
                    };
                    this.$router.replace(this.fun.getUrl("orderpay", orderJson, aroundOrder));
                    return;
                  }
                  if (this.$route.query.just_live_install) {
                    return this.$router.replace(this.fun.getUrl("installationSeverHome", {}, { status: 3 }));
                  }
                  this.$router.replace(this.fun.getUrl("orderpay", orderJson));
                } else {
                  Toast(response.msg);
                  this.submit_active = true;
                  this.clicktag = 0;
                }
              },
              response => {
                this.submit_active = true;
                console.log(response);
              }
            )
            .catch(err => {
              this.submit_active = true;
              console.log(err);
            });
        }
      }
    },
    //删除那个区域代理的地址id
    deleteAddressData() {
      window.localStorage.removeItem("level");
      window.localStorage.removeItem("province_id");
      window.localStorage.removeItem("city_id");
      window.localStorage.removeItem("district_id");
      window.localStorage.removeItem("street_id");
    },

    // 组装json数据
    assembleJson() {
      let json = {
        //公共数据
        address: encodeURIComponent(JSON.stringify(this.currentAddress)),
        goods: JSON.stringify(this.assembleGoods()),
        member_coupon_ids: JSON.stringify(this.assembleCoupons()),
        orders: JSON.stringify(this.assembleDeduction()),
        // 发票
        // invoice_type: this.invoice_list.invoice_type === "electron" ? 0 : 1,
        // rise_type: this.invoice_list.invoice_status === "person" ? 1 : 0,
        // call: this.invoice_list.call,
        // email: this.invoice_list.email,
        // company_number: this.invoice_list.company_number,
        //新的发票-发票插件
        invoice: this.invoice_list,

        mark: this.$route.query.mark || 0,
        dispatch_type_id: this.selected, //配送方式 ，1：快递 ||2：门店自提||3：门店配送（送货上门）||8：自提点
        first_default: this.first_default || "" //是否首次请求，之后的请求都要回传这个参数。没有传这个参数的订单全部按默认首次请求处理
      };
      if(this.checkCouponList_new.length){
        json.new_member_coupon_ids = this.assembleCoupons_new()
      }
      // 分销活动页面购买的商品，带活动id
      if (this.$route.query.activity_id) {
        json.activity_id = this.$route.query.activity_id;
      }

      if (this.$store.state.liveRoomID) {
        json.room_id = this.$store.state.liveRoomID; //带货直播
      }
      if (this.$store.state.share_room_id) {
        json.share_room_id = this.$store.state.share_room_id; //共享直播
      }

      if (this.hasGoodOpenDF) {
        //有商品开启自定义表单
        console.log("有商品开启自定义表单");
        json.order_goods = JSON.stringify(this.assembleGoodsDFData());
      }

      if (this.show_recharge_mobile) {
        //有商品开启话费慢充
        console.log("有商品开启话费慢充");
        json.order_goods = JSON.stringify(this.assembleGoodsTELData());
      }
      if (this.$route.query.electricity == "electricity") {
        json.order_goods = JSON.stringify(this.assembleGoodsTELData());
      }

      //油卡充值
      if (this.oil_account && this.oil_mobile) {
        json.order_goods = JSON.stringify(this.assembleGoodsTELData());
      }

      if (this.cpsType == "1") {
        // 直冲需要填写帐号
        json.recharge_number = this.cpsTxt;
      }

      if (this.camilo_resources_coupon_type == 1) {
        // 直冲需要填写帐号
        json.recharge_number = this.recharge_number;
      }

      if (this.deliveryTimeParams && this.deliveryTimeParams.status == 1) {
        json.delivery_day = this.shop_delivery_day;
        json.delivery_time = this.shop_delivery_time;
      }
      if (this.$route.query.tag == "coffee") {
        json.coffee_pre_order_sn = this.$route.query.coffee_pre_order_sn;
      }

      json = this.handleDataActionBuyUrl(json, "order");
      json = this.handleDataActionCartUrl(json, "order");

      if (this.root_tag == "store") {
        json.store_id = this.store_id;
        json.mobile = this.linkinfo.mobile;
        json.realname = this.linkinfo.name;
        json.cart_ids = JSON.stringify(this.storeCarts);
        let storeTable = JSON.parse(sessionStorage.getItem("storeTable"));
        if (storeTable && storeTable.table_store == this.store_id) {
          json.table_id = storeTable.table_id;
        }
      } else if (this.root_tag == "rentCartBuy" || this.root_tag == "rentBuy") {
        let right = window.localStorage.getItem("rentTimeRight");
        let choose = window.localStorage.getItem("rentTimeChoose");
        let self = window.localStorage.getItem("rentTimeSelf");
        let lease_term = {};

        if (!this.fun.isTextEmpty(choose)) {
          lease_term = choose;
        } else if (!this.fun.isTextEmpty(self)) {
          lease_term = self;
        }

        json.lease_rights = this.fun.isTextEmpty(right) == null ? [] : right;
        json.lease_term = lease_term;
        json.cart_ids = JSON.stringify(_cart_ids);
      }

      if (this.isPhoto) {
        //相册参数
        json.thumbs = this.fileList1;
        json.is_open_photo_order = 1;
      }

      if (this.selected == "8" || this.selected == "12" || this.selected == "15") {
        json.realname = this.distributionUserName;
        json.mobile = this.distributionUserMobile;
      }

      if (this.selected == "8" || this.selected == "12") {
        // 自提点
        json.package_deliver_id = this.selected == "8" ? this.defaultSelfCarry.id : this.o2oSelfCarry.id;
        delete json.address;
      }

      if (this.selected == "10") {
        json.supplier_driver_distribution_address = this.supp_point;
      }
      if (this.selected == "2") {
        json.mobile = this.linkinfo.mobile;
        json.realname = this.linkinfo.name;

        if (this.root_tag === "o2oDeposit") {
          // 门店定金  后端需要把门店的地址给传过去 #86280
          currentAddId = 1; //地址没有id  写死一个
          let arr = this.store_info.store_address.split(" ");
          this.setAddressViewData({
            province: arr[0],
            city: arr[1],
            district: arr[2],
            street: arr[3],
            address: arr[4],
            mobile: this.store_info.store_mobile,
            username: this.store_info.store_name
          });
          json.address = encodeURIComponent(JSON.stringify(this.currentAddress));
          // 设置地址界面
        }
      }
      if (this.selected == "3") {
        json.mobile = this.store_info.store_mobile;
        json.realname = this.store_info.store_name;
      }

      if (this.$route.query.name == "newBlindBox") {
        //新盲盒插件
        json.new_blind_box = {
          select_goods: JSON.parse(this.$route.query.select_goods),
          activity_id: this.$route.query.activity_id
        };
      }

      let feast_system_param = (window.localStorage.getItem("feast_system_param") && JSON.parse(window.localStorage.getItem("feast_system_param"))) || null;
      if (feast_system_param) {
        json.feast_system_param = {
          reportId: feast_system_param.reportId,
          qyDomain: feast_system_param.qyDomain,
          shopId: feast_system_param.shopId,
          tenantId: feast_system_param.tenantId,
          qyCode: feast_system_param.qyCode
        };
      }
      //orderOtherParams 统一添加一些带在链接上的 query参数需要传递到下单页的
      let orderOtherParams = (window.sessionStorage.getItem("orderOtherParams") && JSON.parse(window.sessionStorage.getItem("orderOtherParams"))) || null;
      if (orderOtherParams) {
        for (let key in orderOtherParams) {
          json[key] = orderOtherParams[key];
        }
      }

      if (this.selected == "16") {
        // 门店自提点
        json.ecp_code = this.extra_info.ecp_code;
        json.ecp_number = this.extra_info.ecp_number;
      }

      Object.assign(json, this.orderLocationObj); // 定位信息
      return json;
    },
    // 组装商品信息
    assembleGoods() {
      let newGoods = [];

      for (let j = 0; j < this.goodsInfo.orders.length; j++) {
        for (let i = 0; i < this.goodsInfo.orders[j].order_goods.length; i++) {
          let model = {};
          model.goods_id = this.goodsInfo.orders[j].order_goods[i].goods_id;
          model.total = this.goodsInfo.orders[j].order_goods[i].total;
          model.option_id = this.goodsInfo.orders[j].order_goods[i].goods_option_id;
          newGoods.push(model);
        }
      }
      return newGoods;
    },
    assembleGoodsDFData() {
      //组装商品自定义表单信息
      let newGoodsDF = [];
      for (let j = 0; j < this.goodsInfo.orders.length; j++) {
        for (let i = 0; i < this.goodsInfo.orders[j].order_goods.length; i++) {
          if (this.goodsInfo.orders[j].order_goods[i].diy_form) {
            let modelDF = {};
            modelDF.pre_id = this.goodsInfo.orders[j].order_goods[i].pre_id;
            modelDF.diyform_data_id = this.goodsInfo.orders[j].order_goods[i].diy_form.diyform_data_id;
            newGoodsDF.push(modelDF);
          }
        }
      }
      return newGoodsDF;
    },
    assembleGoodsTELData() {
      //组装商品话费慢充信息
      let newGoodsDF = [];
      let modelDF = {};
      if (this.$route.query.electricity == "electricity") {
        modelDF.pre_id = this.electricity_Guide;
        modelDF.account_id = this.$route.query.account_id;
      } else if (this.oil_account && this.oil_mobile) {
        //油卡充值
        modelDF.pre_id = this.oil_pre_id;
        modelDF.account = this.oil_account;
        modelDF.mobile = this.oil_mobile;
      } else {
        modelDF.pre_id = this.show_recharge_mobile;
        modelDF.mobile = this.recharge_mobile;
      }
      newGoodsDF.push(modelDF);
      return newGoodsDF;
    },
    // 组装优惠券json信息
    assembleCoupons() {
      let coupons = [];
      for (let i = 0; i < this.checkCouponList.length; i++) {
        if (this.is_coupon_SELE) {
          //开启折叠优惠券
          let coupon_arr = this.checkCouponList[i].has_conpon_id;
          coupons = coupons.concat(coupon_arr.slice(0, this.coupons_temp[this.checkCouponList[i].coupon_id].num));
          this.use_coupon_size = coupons.length;
        } else {
          coupons.push(this.checkCouponList[i].id);
        }
      }

      return coupons;
    },
    //新优惠券组装json信息
    assembleCoupons_new() {
      let coupons = [];
      for (let i = 0; i < this.checkCouponList_new.length; i++) {
        coupons.push(this.checkCouponList_new[i].id);
      }
      return coupons;
    },
    // 组装优惠抵扣信息
    assembleDeduction() {
      let deductions = [];
      for (let i = 0; i < this.checkDeductionList.length; i++) {
        deductions.push(this.checkDeductionList[i]);
      }
      return deductions;
    },

    // 初始化优惠券
    initCoupon(coupon) {
      if (coupon.deduction_lang) {
        this.deduction_lang = coupon.deduction_lang;
      }
      if (!coupon) return;
      this.isShowCoupon = coupon.whether_show_coupon == "1" ? true : false;
      this.is_coupon_SELE = coupon.coupon_show == "1" ? true : false;
      if (coupon.member_coupons) {
        this.coupon_size = coupon.member_coupons.length;
        if (this.is_coupon_SELE) {
          let arr2 = coupon.member_coupons.sort((a, b) => {
            return a.expired_at - b.expired_at;
          });
          // this.coupons = coupon.member_coupons;
          this.initSelectCoupon(arr2);
        } else {
          this.coupons = coupon.member_coupons;
        }
      }
      if (coupon.member_new_coupons) {
        this.coupon_size_new = coupon.member_new_coupons.length;
        this.coupons_new = coupon.member_new_coupons;
        this.defaultSelectCoupon_new(this.coupons_new);//初始化
      }
    },
    mustSelectCoupon() {
      // 后台设置，下单前判断有优惠券数量但没使用时，是否提示并展开选择优惠券弹窗，只提示一次！
      if (this.openCueCoupon && this.coupon_size > 0 && this.use_coupon_size < 1 && !this.isCueCoupon) {
        //显示优惠券列表弹窗
        this.isCueCoupon = true;
        this.popupCouponSpecs = true;
        return true;
      }
      return false;
    },
    //初始化新优惠券
    defaultSelectCoupon_new(coupons_new){
      if(coupons_new.length > 0){
        this.checkCouponList_new = [];
        this.use_coupon_size_new = 0;
        coupons_new.forEach((ele,key) => {
          if(ele.checked){
            this.use_coupon_size_new = this.use_coupon_size_new +1;
            this.checkCouponList_new.push(ele)
          }
        });
      }
    },
    //初始化带有默认选中优惠券
    defaultSelectCoupon(coupon) {
      this.coupon_size = coupon.length;
      this.coupons = coupon;
      this.checkCouponList = [];
      coupon.forEach((item, ind) => {
        if (item.checked == true) {
          this.checkCouponList.push(item);
        }
      });
      this.use_coupon_size = this.checkCouponList.length;
    },
    // 配销券
    showDistribution_coupon() {
      this.distribution_couponSpecs = true;
    },
    closeDistribution_coupon() {
      this.distribution_couponSpecs = false;
    },
    ChangeDistribution(id, valid) {
      if (!valid) {
        this.$toast("该配销券不可选");
        return;
      }
      if (this.distribution_coupon_ids.includes(id)) {
        this.distribution_coupon_ids.splice(this.distribution_coupon_ids.indexOf(id), 1);
      } else {
        this.distribution_coupon_ids.push(id);
      }
      this.handleBuy("2");
    },
    confirmDistributtion_coupon() {},
    // 优惠券
    showCoupon() {
      if (this.coupon_size == 0) {
        Toast("暂无优惠券使用");
        return;
      }
      this.popupCouponSpecs = true;
    },
    showCoupon_new() {
      if (this.coupon_size_new == 0) {
        Toast("暂无优惠券使用");
        return;
      }
      this.popupCouponSpecs_new = true;
    },
    selectCoupon_new(value, valObj, num) {
      // 处理选择
      this.screenCoupon_new(value, valObj, num);
      // 设置已经使用多少优惠券
      this.use_coupon_size_new = this.checkCouponList_new.length;

      // 重新计算
      this.handleBuy("2");
    },
    // 选择优惠券
    selectCoupon(value, valObj, num) {
      // 处理选择
      this.screenCoupon(value, valObj, num);
      // 设置已经使用多少优惠券
      this.use_coupon_size = this.checkCouponList.length;

      // 重新计算
      this.handleBuy("2");
    },
    chooseCoupon(index, valid) {
      if(!valid) return;
      this.$refs.checkboxes[index].toggle();
      // if (valid) {
      //   this.coupons[index].checked = true;
      // }
    },
    chooseCoupon_new(index, coupon) {
      if (!coupon.valid) return;
      this.$refs.checkboxes_new[index].toggle();
    },
    screenCoupon_new(value, valObj, num) {
      let tarValue = valObj;
      console.log(this.checkCouponList_new,'this.checkCouponList_new')
      if (value) {
        // 选中添加
        this.cup_notice = false;
        if (this.checkCouponList_new.length > 0) {
          for (let i = 0; i < this.checkCouponList_new.length; i++) {
            if (this.checkCouponList_new[i].id == tarValue.id) {
              this.checkCouponList_new.splice(i, 1);
            }
          }
          this.checkCouponList_new.push(tarValue);
        } else {
          this.checkCouponList_new.push(tarValue);
        }
      } else {
        // 取消选中
        this.cup_notice = true;
        if (this.checkCouponList_new.length > 0) {
          for (let i = 0; i < this.checkCouponList_new.length; i++) {
            if (this.checkCouponList_new[i].id == tarValue.id) {
              this.checkCouponList_new.splice(i, 1);
            }
          }
        }
      }
    },
    // 筛选数据优惠券状态
    screenCoupon(value, valObj, num) {
      let tarValue = valObj;
      if (value) {
        // 选中添加
        this.cup_notice = false;
        if (this.checkCouponList.length > 0) {
          for (let i = 0; i < this.checkCouponList.length; i++) {
            if (this.checkCouponList[i].id == tarValue.id) {
              this.checkCouponList.splice(i, 1);
            }
          }
          this.checkCouponList.push(tarValue);
        } else {
          this.checkCouponList.push(tarValue);
        }

        if (this.is_coupon_SELE && value) {
          //开启折叠优惠券并且为点击复选框为选中状态
          this.coupons_temp[tarValue.coupon_id].num = num || 1;
        }
      } else {
        // 取消选中
        this.cup_notice = true;
        if (this.checkCouponList.length > 0) {
          for (let i = 0; i < this.checkCouponList.length; i++) {
            if (this.checkCouponList[i].id == tarValue.id) {
              this.checkCouponList.splice(i, 1);
            }
          }
        }
        if (this.is_coupon_SELE && !value) {
          //开启折叠优惠券并且为点击复选框为选中状态
          this.coupons_temp[tarValue.coupon_id].num = 0;
        }
      }
    },
    //折叠优惠券
    initSelectCoupon(coupon) {
      let coupon_data = coupon;
      let result = [];
      let temp = {};

      for (let i = 0; i < coupon_data.length; i++) {
        let num = 0; //同类型已选中并符合使用条件的优惠券数量
        let valid = 0; //最高限制使用数量
        let has_conpon_id = [coupon_data[i].id];
        if (coupon_data[i].checked) {
          num++;
        }
        if (coupon_data[i].valid) {
          valid++;
        }
        for (let j = i + 1; j < coupon_data.length; j++) {
          if (coupon_data[i].coupon_id == coupon_data[j].coupon_id) {
            if (coupon_data[j].checked) {
              num++;
            }
            if (coupon_data[j].valid) {
              valid++;
            }
            has_conpon_id.push(coupon_data[j].id);
            coupon_data.splice(j, 1);
            j--;
          }
        }
        let _data = coupon_data[i];
        _data.has_conpon_id = has_conpon_id;
        _data.valid_num = valid;
        result.push(_data);
        temp[coupon_data[i].coupon_id] = {};
        temp[coupon_data[i].coupon_id].num = num;
      }
      this.coupons_temp = temp;
      this.coupons = result;
    },
    // 改变优惠券数量
    changeCoupon(num, data) {
      let valObj = data.name;
      if (num > valObj.valid_num) {
        Toast(`使用张数已达上限`);
        this.stepper_show = 1; //添加原因van-stepper的value只有第一次有
        clearTimeout(this.timer);
        this.timer = setTimeout(() => {
          // 注意此时修改 value 后会再次触发 change 事件
          this.coupons_temp[valObj.coupon_id].num = valObj.valid_num;
          this.stepper_show = 0;
        }, 200);

        // this.$set(this.coupons_temp[valObj.coupon_id], "num", valObj.valid_num);
        return;
      } else if (num == "" || num == undefined || num == 0) {
        Toast("暂不使用请取消勾选");
        return;
      } else {
        clearTimeout(this.timer);
        this.coupons_temp[valObj.coupon_id].num = num;
      }

      let value = {
        target: { checked: true }
      };
      if (this.timeoutId) {
        clearTimeout(this.timeoutId); // 先清除之前的延时，并在下面重新开始计算时间
      }
      // clearTimeout方法，以便控制连续触发带来的无用调用
      this.timeoutId = setTimeout(() => {
        // 200毫秒以后执行方法
        this.selectCoupon(value, valObj, num);
      }, 200); // 如果还没有执行就又被触发，会根据上面的clearTimeout来清除并重新开始计算
    },

    // 抵扣选择响应,运费选择
    discountHandle(item, value, tag) {
      if (this.good_clicktag === 0) {
        if (tag == "discount") {
          this.screenDiscount(item, value);
        } else if (tag == "serviceFee") {
          this.serviceFeesHandle(item, value);
        }

        // 重新计算
        this.handleBuy("2");
      }
    },
    // 是否含税选择响应
    kfeeChange(e, item, value) {
      this.taxInclusive[item.pre_id] = [];
      if (!e) {
        // 选择了含税才传参数
        this.taxInclusive[item.pre_id].push(value.fee_code);
      }
      this.deductionListHandle(item, value);
      // 重新响应页面
      this.handleBuy("2");
    },
    switchChange(item, value, tag) {
      if (value.checked) {
        this.service_fee[item.pre_id] = [];
        this.service_fee[item.pre_id].push(value.code);
        if (tag == "serviceFee") {
          this.serviceFeesHandle(item, value);
        }
        this.handleBuy("2");
      } else {
        this.service_fee[item.pre_id] = [];
      }
    },
    // 留言触发抵扣事件
    noteHandle(event, item) {
      this.deductionListHandle(item);
    },
    // 筛选抵扣
    screenDiscount(item, value) {
      this.deductionListHandle(item, value);
    },
    //服务费、运费复选框
    serviceFeesHandle(item, value) {
      //服务费、运费复选框
      if (this.service_fee[item.pre_id].indexOf("liveInstall") > -1 && !location_loading) {
        location_loading = 1;
        this.fun
          .getLocation()
          .then(res => {
            this.location = res;
            location_loading = 2;
          })
          .catch(err => {
            Toast("定位失败，请手动切换定位！");
            location_loading = 2;
            this.location.address = "定位失败，请手动切换！";
            console.log(err);
          });
      }

      this.deductionListHandle(item);
    },

    // 处理checkDeductionList响应
    deductionListHandle(item, value) {
      let isHasPreId = false;
      if (this.checkDeductionList.length > 0) {
        this.checkDeductionList.forEach((deduction, index) => {
          if (deduction && deduction.pre_id == item.pre_id) {
            isHasPreId = true;
            if (value && value.checked) {
              // 选中的时候检查是否有对应的code
              if (deduction.deduction_ids && deduction.deduction_ids.indexOf(value.code) == -1) {
                deduction.deduction_ids.push(value.code);
              }
            } else if (value && !value.checked) {
              // 取消选中的时候检查去掉对应的code
              if (deduction.deduction_ids && deduction.deduction_ids.indexOf(value.code) > -1) {
                deduction.deduction_ids.splice(deduction.deduction_ids.indexOf(value.code), 1);
              }
            }

            // 留言和安装选项重新赋值
            deduction.service_fee = this.service_fee[item.pre_id];
            deduction.note = this.note[item.pre_id];
            deduction.tax_fee = this.taxInclusive[item.pre_id];
          }
        });
      }
      if (!isHasPreId) {
        this.checkDeductionList.push({
          deduction_ids: value && value.code ? [value.code] : [],
          pre_id: item.pre_id,
          note: this.note[item.pre_id],
          service_fee: this.service_fee[item.pre_id],
          tax_fee: this.taxInclusive[item.pre_id]
        });
      }
      this.checkDeductionList.reverse(); // 更新数组
    },

    // 微信订阅消息
    confirmSub(e) {
      this.submit();
    },
    errorSub(err) {
      this.submit();
    },

    // 修改个人信息
    confirmFrom(e) {
      this.myRealname = e.member_name;
      this.myIdcard = e.member_card;
      this.showFrom = false;
    },
    //更换自提点 （杨朗）
    replaceZT() {
      if(this.root_tag == "communityBuy") return;
      this.save_ztd_LocalStorage(this.distributionUserName, this.distributionUserMobile);
      let _query = {};
      let _params = { goods: JSON.stringify(this.assembleGoods()) };
      if (this.$route.query.goods) {
        _query.goods = this.$route.query.goods;
      }
      if(this.root_tag == "packagBuy" || this.root_tag == "giftBuy"){
        _params.packagJson = this.$route.params.packagJson;
      }
      let selected = Number(this.selected);
      let _isEmptyData = (selected == 8 && this.fun.isTextEmpty(this.defaultSelfCarry)) || (selected == 12 && this.fun.isTextEmpty(this.o2oSelfCarry));
      if (_isEmptyData) {
        _params.noLocation = 1;
      }
      this.toRouter("SelfCarry_info", "replace", _params, _query);
    },
    // 跳转增加域名--应用市场
    toSite() {
      let query = {};
      if (!this.shop_domain) {
        if (this.plugin_id) {
          query = { plugin_id: this.plugin_id };
        }
        this.toRouter("bindingSite", "replace", {}, query);
      }
    },
    toRouter(url, jumpType, params, query) {
      const { i, mid, shop_id, type, ...urlQuery } = this.$route.query;
      let commonJson = {
        form_data_id: this.form_data_id,
        dispatch_id: this.selected
      };
      const allQuery = { ...urlQuery, ...commonJson };
      if (jumpType === "replace") {
        this.$router.replace(
          this.fun.getUrl(
            url,
            {
              ...allQuery,
              ...params
            },
            { ...query }
          )
        );
      } else {
        this.$router.push(
          this.fun.getUrl(
            url,
            {
              ...allQuery,
              ...params
            },
            { ...query }
          )
        );
      }
    },

    // 权益商品选择事件
    rentSelect() {
      // 1.判断是否选择权益商品，有则租期按照会员权益日期计算
      this.clearStorage();
      this.judgeIsRight();
      if (this.isOpenRight) {
        let arr = [];

        this.order_data.forEach(val => {
          val.order_goods.forEach(item => {
            let obj = {
              goods_id: item.goods_id,
              total: item.total
            };
            arr.push(obj);
          });
        });

        window.localStorage.setItem("rentTimeRight", JSON.stringify(arr));

        this.getRentDataActionCart(JSON.stringify(arr), []);
      } else if (!this.isOpenRight) {
        this.currentIndex = "999";
        this.getRentDataActionCart([], []);
      }
    },
    // 判断是否选择权益商品
    judgeIsRight() {
      if (this.isOpenRight) {
        this.isRightChoose = false;
      } else {
        this.isRightChoose = true;
      }
    },
    // 选择租期
    rentTimeChoose(item, index) {
      if (this.root_tag == "yzlease") {
        this.currentIndex = index;
        this.yz_lease_time.days = item.term_days;
        this.yz_lease_time.lease_term_id = item.id;
        console.log(this.yz_lease_time);
        this.handleBuy();
        return;
      }
      if (this.currentIndex == index) {
        this.currentIndex = "999";
        this.clearStorage();
        this.getRentDataActionCart([], []);
      } else {
        this.clearStorage();
        this.currentIndex = index;

        let obj = {
          days: 0,
          lease_term_id: item.id
        };

        window.localStorage.setItem("rentTimeChoose", JSON.stringify(obj));
        this.getRentDataActionCart([], JSON.stringify(obj));
      }
    },
    // 选择自定义租期
    rentSelfChoose() {
      this.clearStorage();
      this.currentIndex = "999";
      this.showPop = true;
    },
    // 确认选择租期
    activation() {
      if (this.fun.isTextEmpty(this.popCode)) {
        this.$dialog.alert({ message: "租期不能为空" });
        return;
      }
      this.showPop = false;
      if (this.root_tag == "yzlease") {
        this.yz_lease_time.days = this.popCode;
        this.yz_lease_time.lease_term_id = 0;
        this.handleBuy();
        return;
      }
      let obj = {
        days: this.popCode,
        lease_term_id: 0
      };

      window.localStorage.setItem("rentTimeSelf", JSON.stringify(obj));
      this.getRentDataActionCart([], JSON.stringify(obj));
    },
    // 清除租赁localStorage
    clearStorage() {
      window.localStorage.removeItem("rentTimeSelf");
      window.localStorage.removeItem("rentTimeChoose");
      window.localStorage.removeItem("rentTimeRight");
    },

    showAgreement() {
      this.agreementShow = true;
    },

    showPay() {
      this.agreementPayShow = true;
    },

    getLocation(_type) {
      this.fun
        .getLocation()
        .then(res => {
          this.getList(res, _type);
        })
        .catch(err => {
          this.isQuest_ing = false;
        });
    },
    //获取自提点列表（杨朗）
    //_type {shop:杨朗||o2o:门店自提}
    getList(_data, type) {
      let _type = type;
      let that = this;
      let p = _data.point ? this.fun.bd_encrypt(_data.point.lng, _data.point.lat) : {};
      let json = {
        city_name: _data.city,
        lat: p.lat || "",
        lng: p.lng || "",
        kwd: "",
        goods: JSON.stringify(this.assembleGoods())
      };
      if (this.$route.query.package_deliver_id) {
        json.deliver_id = this.$route.query.package_deliver_id;
      }
      this.isQuest_ing = true;
      let _url = "plugin.package-deliver.frontend.deliver.getList";
      if (_type == "o2o") {
        _url = "plugin.package-deliver.frontend.store.deliver.getList";
        json.store_id = this.$route.query.store_id;
      }
      $http.get(_url, json).then(
        response => {
          that.isQuest_ing = false;
          if (response.result === 1) {
            if (_type == "shop") {
              that.deliverName = response.data.name;
              if (that.fun.isTextEmpty(that.defaultSelfCarry.id)) {
                that.defaultSelfCarry = response.data.list.data[0] ? response.data.list.data[0] : ""; //没有就取第一个为默认自提点。。。
              }
            } else if (_type == "o2o") {
              that.o2odeliverName = response.data.name;
              if (that.fun.isTextEmpty(that.o2oSelfCarry.id)) {
                that.o2oSelfCarry = response.data.list.data[0] ? response.data.list.data[0] : ""; //没有就取第一个为默认自提点。。。
              }
            }
          } else {
            Toast(response.msg);
          }
        },
        response => {
          that.isQuest_ing = false;
          console.log(response);
        }
      );
    },

    // 循环订单判断是否开启话费慢充和自定义表单
    findGoodOpen() {
      for (let j = 0; j < this.goodsInfo.orders.length; j++) {
        if (this.goodsInfo.orders[j].camilo_resources_coupon_type) {
          // 卡券商品
          this.camilo_resources_coupon_type = this.goodsInfo.orders[j].camilo_resources_coupon_type;
          // 取消默认地址
          // if (this.plugin_setting.yz_supply_camilo_resources.is_default_order_address == 1) {
          //   // 是否开启默认地址
          //   this.show_address = true;
          //   currentAddId = 1; //地址没有id  写死一个
          //   let { address, city, district, province, street, mobile, username } = this.plugin_setting.yz_supply_camilo_resources;
          //   this.setAddressViewData({
          //     address,
          //     city,
          //     district,
          //     province,
          //     street,
          //     mobile,
          //     username
          //   }); // 设置地址界面
          // }
        }
        if (this.bookingShowAddress == "0") {
          //第三方周边游，bookingShowAddress等于0，周边游不需要填写地址，但是商城中台需要填写地址下单
          this.show_address = true;
        }
        if (this.$route.query.electricity == "electricity") {
          // 如果是电费充值
          this.electricity_Guide = this.goodsInfo.orders[j].order_goods[0].pre_id;
          this.ele_no_showAdress = this.goodsInfo.orders[j].order_goods[0] ? this.goodsInfo.orders[0].not_show_address : "";
          this.eleUser = this.goodsInfo.orders[j].order_goods[0] ? this.goodsInfo.orders[0].user_account : "";
        }
        if (this.goodsInfo.orders[j].require_mobile) {
          console.log("有商品开启话费慢充！！！");
          this.recharge_tips = this.goodsInfo.orders[j].tips;
          this.show_recharge_mobile = this.goodsInfo.orders[j].order_goods[0].pre_id;
        }
        //油卡充值
        if (this.oil_account && this.oil_mobile) {
          this.oil_pre_id = this.goodsInfo.orders[j].order_goods[0].pre_id;
        }
        for (let i = 0; i < this.goodsInfo.orders[j].order_goods.length; i++) {
          if (this.goodsInfo.orders[j].order_goods[i].diy_form) {
            console.log("有商品开启自定义表单！！！");
            this.hasGoodOpenDF = true;
          }
        }
      }
    },
    isAllDFOk() {
      //判断是否有商品开启自定义表单但是没有提交的，没提交过的diyform_data_id为0
      let that = this;
      if (this.goodsInfo.orders) {
        for (let j = 0; j < this.goodsInfo.orders.length; j++) {
          for (let i = 0; i < that.goodsInfo.orders[j].order_goods.length; i++) {
            if (that.goodsInfo.orders[j].order_goods[i].diy_form && that.goodsInfo.orders[j].order_goods[i].diy_form.diyform_data_id == 0) {
              console.log("有未填写的表单！！！");
              return false;
            }
          }
        }
        return true;
      }
    },
    diyFormSave(_dyData) {
      console.log("diyFormPopup组件它点击提交了,这是它的数据", _dyData);
      let that = this;
      for (let j = 0; j < this.goodsInfo.orders.length; j++) {
        for (let i = 0; i < that.goodsInfo.orders[j].order_goods.length; i++) {
          if (that.goodsInfo.orders[j].order_goods[i].pre_id == that.activeDYGoodID) {
            that.goodsInfo.orders[j].order_goods[i].diy_form.diyform_data_id = _dyData;
            that.oldOrder_data = that.goodsInfo;
            that.dyFormPopup = false;
            return;
          }
        }
      }
    },
    getGoodDFData(_gID, _dyID, _fDataID, key) {
      this.goodDYDormID = _dyID;
      this.activeDYGoodID = _gID;
      this.activeFormDataID = _fDataID;
      let that = this;
      let _json = {
        form_id: _dyID
      };
      if (_fDataID) {
        _json.form_data_id = _fDataID;
      }
      $http.get("plugin.diyform.api.diy-form.getSingleFormData", _json).then(
        response => {
          if (response.result === 1) {
            that.dfData = response.data;
            that.dyThumb = response.data.thumb ? response.data.thumb : null;
            that.dyDescription = response.data.description ? response.data.description : null;
            that.dyTiitle = response.data.title ? response.data.title : "表单信息";
            if (key == "code") {
              that.codeShow = true;
            } else {
              that.dyFormPopup = true;
            }
          } else {
            that.$dialog.alert({ message: response.msg });
          }
        },
        response => {
          console.log(response);
        }
      );
    },

    //下单页优化提货人姓名和电话自动填上上次填写的信息【任务编号: 35632】
    save_ztd_LocalStorage(_name, _mobile) {
      let _memberInfoes = {
        distributionUserName: _name,
        distributionUserMobile: _mobile
      };
      localStorage.setItem("selfCarryInfo", JSON.stringify(_memberInfoes));
    },
    getDistributionInfo(data = null) {
      // 获取已有的自提点提货人、姓名信息记录
      //是否保存过自提点提货人和手机号信息，有的话自动填写【任务编号: 35632】
      let { mobile, realname } = data || {}; //接口返回记录的数据
      let apiData = { distributionUserMobile: mobile, distributionUserName: realname };

      let { distributionUserMobile, distributionUserName } = this.$route.query; //链接传入
      let queryData = { distributionUserMobile, distributionUserName }; //链接传入
      let storageData = {};
      try {
        storageData = JSON.parse(window.localStorage.getItem("selfCarryInfo")) || {}; //localStorage保存
      } catch (error) {
        storageData = window.localStorage.getItem("selfCarryInfo") || {}; //localStorage保存
      }

      if (!this.linkinfo.name) this.linkinfo.name = queryData.distributionUserName || storageData.distributionUserName || apiData.distributionUserName;
      if (!this.linkinfo.mobile) this.linkinfo.mobile = queryData.distributionUserMobile || storageData.distributionUserMobile || apiData.distributionUserMobile;
      if (!this.distributionUserName) this.distributionUserName = queryData.distributionUserName || storageData.distributionUserName || apiData.distributionUserName;
      if (!this.distributionUserMobile) this.distributionUserMobile = queryData.distributionUserMobile || storageData.distributionUserMobile || apiData.distributionUserMobile;
    },
    // 门店配送-查看配送范围
    showDeliveryMap() {
      this.deliveryScopeShow = true;
    },
    showLocationPop() {
      if (location_loading != 2) return;
      this.showLocation = true;
    },
    confirmLocation(data) {
      this.location = data;
    },
    onConfirmShopDeliveryDay(time) {
      this.shop_delivery_day = time.Format("yyyy-MM-dd");
      let now = new Date().Format("yyyy-MM-dd");// 获取当前时间
      // 如果shop_delivery_day为当天，则shop_delivery_time清空，防止选择到比当前时间早的时间
      if (this.shop_delivery_day == now) {
        this.shop_delivery_time = "";
        // 获取当前的小时
        let hour = new Date().getHours();
        // 获取this.deliveryTimeParams.time第n个到最后一个
        this.deliveryTimeParamsTime = this.deliveryTimeParams.time.slice(hour);

      } else {
        this.deliveryTimeParamsTime = this.deliveryTimeParams.time;
      }
      this.shop_delivery_dayPicker = false;
    },
    onConfirmShopDeliveryTime(time) {
      this.shop_delivery_time = time;
      this.shop_delivery_timePicker = false;
    },
    // 蛋糕叔叔的功能代码
    getRule() {
      let query = {
        city: this.cakeCity,
        goods_id: this.$route.query.goodsId,
        lng: this.cakeLng,
        lat: this.cakeLat
      };
      $http.get("plugin.yz-supply-cake.frontend.index.index.getStore", query, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            this.storeList = res;
          } else {
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    onCakeChange(value) {
      if (this.address === "" && this.addressData) {
        //判断是否有默认地址
        this.address = this.addressData?.address;
      }
      if (!this.address) {
        Toast("请先选择地址");
        return;
      }
      if (value) {
        this.cakeMoblie = this.mobile;

        this.cakeChecked = value;
      } else {
        this.cakeMoblie = "";
        this.cakeChecked = value;
      }
    },
    deliveryClick(event, index) {
      this.selected = event;
      this.cakeShipType = event;
      if (event === "shop") {
        //门店自提
        this.deliveryDates = this.shopCakeArr;
      } else {
        this.deliveryDates = this.deliveryArr;
      }
      let dates = this.deliveryDates;
      if (dates.length > 0) {
        let cakeCurrentTime = dates[0]?.date;
        let cakeEndTime = dates[dates.length - 1]?.date;
        let startTime = new Date(cakeCurrentTime);
        let endTime = new Date(cakeEndTime);
        this.cakeStartTime = startTime;
        this.cakeEndTime = endTime;
      }
      this.handleBuy();
    },
    cakePopup(value) {
      this.show["Cake"] = true;
      //配送时间弹窗
      // let item = event.currentTarget.dataset.name;
      // this.setData({
      //   [item]: true
      // });
    },
    showCakePopup() {
      if (this.deliveryDates.length > 0) {
        this.showCake = true;
      } else {
        Toast("没有配送日期");
      }
    },
    cakeTimePopup() {
      //配送时间弹窗
      if (this.cakeShipDate) {
        this.cakeTimeShow = true;
      } else {
        Toast("请先选择配送日期");
      }
    },
    deliveryCancel(item) {
      this[item] = false;
    },
    deliveryConfirm(value) {
      let time = value.getTime();
      let cakeTime = this.timestampToTime(time);
      let timeData = new Date(new Date(cakeTime).toLocaleDateString()).getTime();
      let datasArr = this.deliveryDates;
      let deliveryObj = datasArr.find(item => {
        let itemTime = new Date(new Date(item.date).toLocaleDateString()).getTime(); //需要处理好时间才相等
        return timeData === itemTime;
      });
      let deliveryArr = [];
      if (this.cakeShipType === "delivery") {
        //商家配送逻辑
        deliveryArr = deliveryObj.validate_delivery_times ? deliveryObj.validate_delivery_times : []; //处理配送时间
        this.deliveryAmount = deliveryObj.delivery_amount;
        this.handleBuy();
      } else {
        deliveryArr = deliveryObj.validate_take_times || []; //处理配送时间
      }
      let timerData = [];
      deliveryArr = Array.from(deliveryArr); //处理数组格式
      deliveryArr.forEach(item => {
        timerData.push({
          text: item,
          checked: false
        });
      });

      this.cakeShipDate = cakeTime;
      this.showCake = false;
      this.takeDates = timerData;
    },
    cakeTimeChange(text, index) {
      for (let i in this.takeDates) {
        this.takeDates[i].checked = false;
      }

      this.takeDates[index].checked = true;
      this.cakeText = text;
    },
    cakeTimeConfirm() {
      this.cakeTimeShow = false;
      this.shipTimeText = this.cakeText;
    },
    formatDate(timestamp) {
      if (!timestamp) return;
      let date = new Date(Number(timestamp)); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      let year = date.getFullYear();
      let month = date.getMonth() + 1; // 注意月份是从0开始的，所以需要+1
      let day = date.getDate();
      let hours = date.getHours();
      let minutes = date.getMinutes();
      let seconds = date.getSeconds();

      // 使用padStart方法确保月份、日期、小时、分钟和秒都是两位数
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      hours = hours < 10 ? "0" + hours : hours;
      minutes = minutes < 10 ? "0" + minutes : minutes;
      seconds = seconds < 10 ? "0" + seconds : seconds;
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    timestampToTime(timestamp) {
      if (!timestamp) return;
      var date = new Date(Number(timestamp)); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
      let Y, M, D;
      if (this.fun.isIosOrAndroid() === "ios") {
        Y = date.getFullYear() + "/";
        M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "/";
        D = this.change(date.getDate()) + " ";
      } else {
        Y = date.getFullYear() + "-";
        M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
        D = this.change(date.getDate()) + " ";
      }

      return Y + M + D;
    },
    change(t) {
      if (t < 10) {
        return "0" + t;
      } else {
        return t;
      }
    },
    formatter(type, val) {
      if (type === "year") {
        return val + "年";
      }
      if (type === "month") {
        return val + "月";
      }
      if (type === "day") {
        return val + "日";
      }
      return val;
    },
    gotochangeCake() {
      this.cakeStoreShow = true;
    },
    travelConfirm(value) {
      let time = value.getTime();
      this.travelAroundTime = this.formatDate(time);
      this.showTravel = false;
    },
    cakeData(data) {
      let cakeRule = data.orders[0]?.yz_supply_cake_distribution_rule?.data || {};
      if (Object.keys(cakeRule).length > 1) {
        //判断是否为空对象，没有获取到城市，城市必填
        this.canSame = cakeRule.can_same;
        this.canTake = cakeRule.can_take;
        this.canShip = cakeRule.can_ship;
        let { cakeShipDate, shipTimeText } = "";
        this.cakeDeliveryArr = [];
        let dispatch = [];
        if (this.canTake === "1") {
          dispatch.push({
            dispatch_type_id: "shop",
            name: "门店自提"
          });
        }
        if (this.canShip === "1") {
          dispatch.push({
            dispatch_type_id: "delivery",
            name: "商家配送"
          });
        }
        if (this.canSame === "1") {
          dispatch.push({
            dispatch_type_id: "same",
            name: "快递"
          });
          cakeShipDate = false;
          shipTimeText = cakeRule.delivery_text;
          this.cakeShipDate = cakeShipDate;
        }
        this.cakeDeliveryArr = dispatch;
        if (this.cakeShipType == "") {
          //默认第一次蛋糕叔叔是没有类型的，需要有一个默认配送方式类型
          this.selected = this.cakeDeliveryArr[0]?.dispatch_type_id;
          this.cakeShipType = this.cakeDeliveryArr[0]?.dispatch_type_id;
        }
        this.cakeDeliveryArr.forEach((item, index) => {
          if (item.dispatch_type_id === this.selected) {
            this.selected = item.dispatch_type_id;
            this.cakeShipType = item.dispatch_type_id;
          }
        });
        if (this.cakeShipType) {
          //没有配送方式的时候不执行获取配送时间
          let dates = []; //获取配送时间的
          if (this.cakeShipType === "delivery") {
            dates = cakeRule.validate_delivery_dates; //处理配送时间
            this.deliveryArr = cakeRule.validate_delivery_dates;
            this.deliveryAmount = this.deliveryArr[0]?.delivery_amount; //默认运费就传第一个
          } else {
            dates = cakeRule.validate_take_dates; //处理配送时间
          }
          this.shopCakeArr = cakeRule.validate_take_dates;
          this.deliveryDates = dates;
          let cakeCurrentTime = dates[0]?.date;
          let cakeEndTime = dates[dates.length - 1]?.date;
          let startTime = new Date(cakeCurrentTime);
          let endTime = new Date(cakeEndTime);
          this.shipTimeText = shipTimeText;
          this.cakeStartTime = startTime;
          this.cakeEndTime = endTime;
        }
      }
    },
    showDetail(detail) {
      let cakeDetail = JSON.stringify(detail);
      if (detail) {
        window.localStorage.setItem("cakeStoreDetail", cakeDetail);
      }
      this.cakeStoreShow = false;
      this.shopId = detail.shop_id;
      this.shopName = detail.shop_name;
      this.shopDetail = detail.address;
    },
    setDataVal(name,val,val2){
      // this[name][name2] =val
      if(val2 != undefined){
        this.$set(this[name], val, val2);
      } else {
        this[name] = val;
      }
    },
    onChangeEcp(){
      this.requestByAddress();
      this.setDataVal('extra_info','ecpLogPop',false);
    },
    async getEcpList() {
      if(this.extra_info.ecpList) return this.extra_info.ecpLogPop = true;
      let { result, msg, data } = await $http.get("plugin.ecpay-logistics.frontend.index.get-list",{},".");
      if (result == 0) return this.$toast(msg);
      this.setDataVal('extra_info','ecpList',data);
      this.setDataVal('extra_info','ecpLogPop',true);
    },
    selectEcpItem(item){
      this.setDataVal('extra_info','ecp_code',item.code);
      this.setDataVal('extra_info','sleectEcp',item.name);
    }
  },
  components: { deliveryMap, yzAddressList, location, yzSubscribe, yz_uploader, yzMyinfo, order_invoice, diyfrom, addGoodsModule, invoicePop, cityDeliveryDay, agencySaleman, broadnetCard }
};
